DelphiFAQ Home Search:

How can I rename table names and column names in mysql

 

comments9 comments. Current rating: 5 stars (4 votes). Leave comments and/ or rate it.

If only a few changes are necessary, you can just go through a web administration tool like phpAdmin.

If you have many names to change, you could write a script (possibly even generate a script by a tool) and execute it like this:

mysql DATABASENAME -uUSERNAME -pPASSWORD <SCRIPTFILE

The script would contain the SQL commands as shown here:

alter table orgs change o_id org_id int(11);
alter table orgs change o_name org_name varchar(64);
rename table orgs organizations;

Comments:

2007-01-29, 00:15:31
anonymous from India  
rating
thanks i have used it
2007-02-28, 09:12:57
anonymous from United States  
Exactly what I needed - thanks
2007-05-16, 23:05:29
anonymous from India  
Thanks
2007-06-11, 23:22:50
anonymous  
rating
2007-12-10, 01:36:20   (updated: 2007-12-10, 01:37:02)
anonymous from Spain  
just be aware... if your table is large this can take a very long time!!!
(its not just a matter of changing column names - mysql has to mess about with EVERY row).
PS. i am not in Spain (go figure?!)
2008-01-09, 23:28:15
saeid.zebardast@gmail.com from Tehran, Iran  
rating
Thanks
2008-03-27, 08:56:16
anonymous from Germany  
thx
2008-05-20, 12:27:40
anonymous from United States  
a good tip.. thanks
2008-05-25, 08:18:14   (updated: 2008-05-25, 08:18:41)
dd from United States  
rating
Thanks, helped a lot since I am just learning SQL and using mySQL.

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.