MySql: Add a Column at a Specific Position
I'm playing with MySql for the 1st time in my life recently. Rather quickly I'm getting used to it mostly due to my experience with MSSQL as DBA.
While changing table structure I just came across one interesting feature and decided to post about it.
It is possible to use MySql ALTER TABLE command and add a column at a specific position within a table row using AFTER command. MSSQL for example cannot do the same within ALTER TABLE and in order to perform such manipulation one need to create and drop temporary table.
"To add a column at a specific position within a table row, use FIRST or AFTER col_name. The default is to add the column last. You can also use FIRST and AFTER in CHANGE or MODIFY operations to reorder columns within a table."
Example:
ALTER TABLE Product ADD Price DECIMAL(10, 2) NOT NULL AFTER ProductName;
Wednesday, May 28, 2008 7:17 PM