简体   繁体   中英

Best way to migrate increment ID and convert to Guid

I have two questions relating to migrating SQL data:

1. Migrate increment ID from db1.table to db2.table (different database)

Example:

在此处输入图片说明

My nightmare is when I have to move data for these 3 tables from one database to another database. The id in two database is not identical.

For now, my best practice is after migrating Guest and Room tables, I will use Excel with Vlookup to update all GuestId and RoomId in table Booking with new ID and after that migrating all these modified data.

Question: are there any better ways to go through this nightmare?

Please note that in this example, only 3 tables mentioned but in my real situation, it is not less than 5 tables joining together...

2. Migrate from IncrementId to Guid

For new project design, I'm using unique Guid instead of traditional increment ID for the table's primary key.

Question: What is the best practice to migrate old SQL Server table from incremented Id to Guid?

EDIT: I'm using SQL Server 2012 and can even use Entity Framework to access my database. So as long as it can help, SQL script or C# programming code are both useful

You could add an extra column to the target database as an int ExternalID (or similar) and copy the original int identifier into that column. Your migration process then needs to refer to that column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM