Portal Home > Knowledgebase > Articles Database > Updating a MySQL field
Updating a MySQL field
Posted by FinalFrontier, 11-11-2011, 05:15 AM |
I am trying to update a MySQL field name, but not having any luck:
UPDATE delivery SET country = 'British Virgin Islands' WHERE country = 'Virgin Islands British';
Does anyone know where I am going wrong?
|
Posted by barbus, 11-11-2011, 06:32 AM |
Try:
SELECT FROM delivery WHERE country = 'Virgin Islands British';
|
Posted by FinalFrontier, 11-11-2011, 06:39 AM |
Thats just going to select it? I need to rename it from Virgin Islands British to British Virgin Islands
|
Posted by foobic, 11-11-2011, 07:14 AM |
There's nothing obviously wrong with your update statement, which suggests that your database isn't quite like you expect (perhaps the structure, or the current content of that entry). If you'd like to post the results of these queries it may help us to see what's up:
|
Posted by FinalFrontier, 11-11-2011, 07:22 AM |
I think I see what your trying to say. You want to know about my tables internal parameters, right?
i41DOTtinypicDOTcom/axiateDOTpng
|
Posted by lynxus, 11-11-2011, 07:24 AM |
As mentioned , Run this command:
SELECT FROM delivery WHERE country = 'Virgin Islands British' LIMIT 10;
If you get zero results then its not going to update as nothing is there to update.
|
Posted by FinalFrontier, 11-11-2011, 07:35 AM |
I got....:
|
Posted by imh-bradm, 11-11-2011, 09:30 AM |
Hi FinalFrontier,
1. Where are you running this command? Is if from the command line, or is it from within phpMyAdmin?
2. What happens when you run it? Do you get any error messages? What do you see?
Also, in regard to the last comment, you can try:
Be sure to have the * symbol after SELECT.
|
Posted by FinalFrontier, 11-11-2011, 10:44 AM |
foobic was correct in that there was nothing wrong with my initial command. The problem was that the entry I wanted to change was "Virgin Islands, British"... I left out the comma! Facepalm!!!!!!!!!!
Thanks for your efforts anyway, gentlemen!
Solved.
|
Posted by lynxus, 11-11-2011, 10:51 AM |
Easy mistake
Also while your here, Look up "reserved keywords" on mysql..
While this isnt your current issue, Ive spent many hours punching the computer when a sql query wouldnt work just to find out i had used a reserved keyword.
Thought id share that nugget of info considering the pain it causes if your not aware of them
|
Posted by webhostmaniac, 11-11-2011, 03:24 PM |
UPDATE delivery SET country =("British Virgin Islands") WHERE country = 'Virgin Islands British';
hence the table is called delivery and column is called country
country would have to = Virgin Islands British exactly, best to use the id of the row
|
Posted by MrKenTX, 11-17-2011, 02:16 AM |
Just a friendly bit of SQL programming advice. Every UPDATE statement should begin as a SELECT statement. That way you always know your WHERE clause is correct.
|
Add to Favourites Print this Article
Also Read
Report abuse? (Views: 825)