Avatar of pixuk
pixuk
 asked on

How to import an identity value in MySQL

I'm moving a large forum database from MSSQL to MySQL, converting to the new forum format with a php script, but in order to make sure I can keep my users attached to their posts, PMs and various other things in the database, I'd like to be able to bring in their ID from MSSQL rather than have MySQL autonumber the ID. In MSSQL this was Enable Identity Insert, but I can't seem to find an equivalent for MySQL.

I suspect it can do this, I'm just not seeing the wood for the trees ;)
MySQL Server

Avatar of undefined
Last Comment
k_murli_krishna

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
racek

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
k_murli_krishna

Migrate your MSSQL table(s) data to simple temporary MySQL table(s) without identity. Now create an empty MySQL table(s) with auto_increment identity  column definition that matches with data that came in from MSSQL.

Now, simply do an INSERT INTO <id_col_table> SELECT * FROM <non_id_col_table> within MySQL itself and drop the simple temporary table(s). This is required since there is no IDENTITY_INSERT in MySQL like MSSQL and one cannot add a auto_increment identity column with an alter table.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes