简体   繁体   English

迁移增量ID并转换为Guid的最佳方法

[英]Best way to migrate increment ID and convert to Guid

I have two questions relating to migrating SQL data: 我有两个与迁移SQL数据有关的问题:

1. Migrate increment ID from db1.table to db2.table (different database) 1.将增量ID从db1.table迁移到db2.table (不同的数据库)

Example: 例:

在此处输入图片说明

My nightmare is when I have to move data for these 3 tables from one database to another database. 我的噩梦是我必须将这3个表的数据从一个数据库移到另一个数据库。 The id in two database is not identical. 两个数据库中的ID不相同。

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. 现在,我的最佳实践是在迁移GuestRoom表之后,我将使用带有Vlookup Excel用新ID更新表Booking所有GuestIdRoomId ,然后迁移所有这些修改的数据。

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... 请注意,在此示例中,仅提及3个表,但在我的实际情况下,不少于5个表连接在一起...

2. Migrate from IncrementId to Guid 2.从IncrementId迁移到Guid

For new project design, I'm using unique Guid instead of traditional increment ID for the table's primary key. 对于新项目设计,我使用唯一的Guid代替表的主键的传统增量ID。

Question: What is the best practice to migrate old SQL Server table from incremented Id to Guid? 问题:将旧的SQL Server表从增量ID迁移到Guid的最佳实践是什么?

EDIT: I'm using SQL Server 2012 and can even use Entity Framework to access my database. 编辑:我正在使用SQL Server 2012,甚至可以使用实体框架来访问我的数据库。 So as long as it can help, SQL script or C# programming code are both useful 因此,只要有帮助,SQL脚本或C#编程代码都是有用的

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. 您可以将一个额外的列作为int ExternalID(或类似)添加到目标数据库,然后将原始int标识符复制到该列中。 Your migration process then needs to refer to that column. 然后,您的迁移过程需要参考该列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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