Specify Primary Key

Posts   
 
    
smurrell
User
Posts: 59
Joined: 22-Feb-2007
# Posted on: 26-Jan-2010 13:14:06   

Hello

I have a bunch of entities which I am replicating from a SQL Server database to a SQL Server CE database. I would like to know how I can carry the primary keys across and force them on the CE database without the CE database auto generating a new primary key. I know I can change the table in CE not to auto increment but to do this each time I update the CE schema is a mission. How can it be done via code?

Regards, Simon

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 26-Jan-2010 20:52:16   

run a "SET IDENTITY_INSERT ON" command on the target database before the update - this allows you to insert existing values in to an auto-increment column.

Remember to "SET IDENTITY_INSERT OFF" at the end .

Matt