MySQL Rename Field

To rename a field, there are loads of examples and different syntax on the web, so I thought I would blog the only one that works for me:

ALTER TABLE <table_name>
    CHANGE COLUMN <field_name> <new_field_name>;

I think you have to specify the field type even if you aren’t changing it.

ALTER TABLE clients
    CHANGE COLUMN telephone telephonenumber
    VARCHAR(40) DEFAULT NULL;

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>