Log in

View Full Version : rename a column?



traq
10-09-2009, 04:16 AM
After a few hours' study, it seems I must delete my column and create a new one in its place. Or am I missing the syntax to rename a column (preserving the data it holds)?

(MySQL 5)

thanks, everyone

forum_amnesiac
10-09-2009, 10:35 AM
I use PHPMYADMIN and that allows you to rename a field.

I opened the table, selected the field and chose the change/edit option.

The first value was the name of the field, I changed this and it preserved the data.

If I was to change the data type then I don't believe it would preserve the data.

Here is the SQL it generated:



ALTER TABLE `table1` CHANGE `field1` `field2` VARCHAR( 30 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL

traq
10-09-2009, 02:07 PM
hey, cool... here I was, looking through every tutorial I could find, and I could've just opened up myadmin...

thanks, I'll try it out.

NXArmada
10-09-2009, 06:51 PM
Check this out from the MySQL site http://dev.mysql.com/doc/refman/5.1/en/alter-table.html