Thursday, January 5, 2012

Add a column to an existing MySQL table

To add a column called new_column to a table called table_name with a datatype of VARCHAR(20), use the following SQL statement:

ALTER TABLE table_name ADD new_column VARCHAR(20);
This statement will add the new column new_column to the end of the table. To insert the new column after a specific column, such as old_column, use this statement:
ALTER TABLE table_name ADD new_column VARCHAR(20) AFTER old_column;
To add the new column as the first column, we can use the following mysql statement:
ALTER TABLE table_name ADD new_column VARCHAR(60) FIRST;

No comments:

Post a Comment