Thursday, 19 April 2012

Add new columns to table in MySQL

The ALTER TABLE command can be used to add new columns to an existing table in a MySQL database:
ALTER TABLE table_name
ADD column_name datatype (eg. tinytext)
To add the column after an specific existing column add:
AFTER existing_column
To add multiple columns with the same statement a number of ADD commands can be chained together and separated with commas:
ALTER TABLE table_name
ADD social_url_twitter tinytext,
ADD social_url_facebook tinytext,
ADD social_url_blogger tinytext