I acquired a database from another developer. He didn’t use auto_incrementers on any tables. They all have primary key ID’s, but he did all the incrementing manually, in code.
Can I turn those into Auto_incrementers now?
Wow, very nice, thanks a ton. It worked without a hitch on one of my tables. But a second table, i’m getting this error…Error on rename of ‘.\DBNAME#sql-6c8_62259c’ to ‘.\DBNAME\dealer_master_events’
For example, here’s a table that has a primary key but is not
AUTO_INCREMENT:You can
MODIFYthe column to redefine it with theAUTO_INCREMENToption:Verify this has taken effect:
Outputs:
Note that you have modified the column definition in place, without requiring creating a second column and dropping the original column. The
PRIMARY KEYconstraint is unaffected, and you don’t need to mention in in theALTER TABLEstatement.Next you can test that an insert generates a new value:
Outputs:
I tested this on MySQL 5.0.51 on Mac OS X.
I also tested with
ENGINE=InnoDBand a dependent table. Modifying theidcolumn definition does not interrupt referential integrity.To respond to the error 150 you mentioned in your comment, it’s probably a conflict with the foreign key constraints. My apologies, after I tested it I thought it would work. Here are a couple of links that may help to diagnose the problem: