Results 1 to 4 of 4

Thread: rename a column?

  1. #1
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default rename a column?

    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

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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:


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

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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.

  4. #4
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    Check this out from the MySQL site http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
    Ryan
    Sevierville, TN

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •