/* Add new auto-incrementing field */
ALTER TABLE dbo.YourTable
ADD ID INT IDENTITY;
/* Make it the primary key */
ALTER TABLE dbo.YourTable
ADD CONSTRAINT PK_YourTable
PRIMARY KEY(ID);
/*
http://dev.mysql.com/doc/refman/5.5/en/alter-table-examples.html
Add new auto-incrementing field and
make it the primary key
MySQL version 5.5.42-cll
*/
ALTER TABLE YourTable
ADD NewFieldName INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY (NewFieldName);
/* move column to the first position
http://stackoverflow.com/questions/29838981/how-to-move-mysql-table-column-to-first-position
WHEN MOVING ID COLUMN, SOMETHING BREAKS AND IDS TRY TO DUPLICATE RESULTING IN
THE RECORD NOT BEING SAVED GORDON NOV 2015
*/
ALTER TABLE YourTable MODIFY COLUMN YourFieldName int(10) FIRST
/* move column to anything other than the first position
http://stackoverflow.com/questions/6805426/how-to-move-columns-in-a-mysql-table
*/
ALTER TABLE YourTable MODIFY `column_you_want_to_move` DATATYPE AFTER `anothercolumn`