Copying a table into another table but preserving the same auto increment key

auto-increment, mysql, sql

Solution

The answers above are good, but on MS SQL you can't insert auto increment value unless if you execute turn identiy_insert off:

`SET IDENTITY_INSERT stock OFF;`

`INSERT INTO stock ( stock_id,stock_item) VALUES (5,'itemE');`

`SET IDENTITY_INSERT stock ON;`

This is EXCATLY what I was looking for. Thank you all :)

Problem

I have a table A filled with records. I created a table B with same columns, and I want to copy all contents of A to B. However, table A has an auto incremented key, so if i had first three records (1,'itemA') (2,'itemB') (5,'itemE') (assuming that 3,4,5 where deleted later). Those recors will be inserted into table B as (1,'itemA') (2,'itemB') (3,'itemE'). Is there a way to insert them exactly the same ? Another thing is, table A is on mySql, and table B is on MS SQL Server

Original source