I've just handled emigrate quite a large database from SQL Server to MySQL. I did not set the main secrets to auto increment throughout the migration since the tables have associations according to ids as primary secrets that are foreign secrets in another table.
Let's focus on adding new records I wish to affect the primary key 'id' posts in most tables to become autoincrement but beginning in the last greatest number within the id column in every table.
What's the easiest method to do that without losing the associations I curently have?
UPDATE: Attempting to add autoincrement provides me with this error:
ERROR 1067: Invalid default value for 'id' SQL Statement: ALTER TABLE `skandium`.`brands` CHANGE COLUMN `id` `id` INT(11) NOT NULL DEFAULT '0' AUTO_INCREMENT ERROR 1050: Table 'brands' already exists SQL Statement: CREATE TABLE `brands` ( `id` int(11) NOT NULL DEFAULT '0', `brand` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1
Just add the car-increment in your needed posts. It will not affect existing rows. It'll begin with the following available value.
Observe that a column being auto-increment means exactly that if you do not assign something into it you will be added in by MySQL. If you wish to supply explicit values that can be done without anything special happening. So you might have set individuals posts to auto-increment immediately.
A column with auto-increment cannot come with an explicit default value.