Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 MS SQL Server 2005 上,我有一个要替换的表。许多其他表都有对此表的外键引用。有没有我可以运行的脚本来简单地将所有这些引用从旧表滚动到新表?
还是我必须仔细检查并专门删除这些外键中的每一个,并为每个外键编写一个新键?
您可以更安全地为新表删除并重新创建它们。
或者,您可以为要替换的旧表中的新表重复使用相同的主键吗?然后您根本不必更新 FK。
如果主键是自动递增的“Identity”列,您可以使用“Set Identity_Insert On”,以允许您使用显式值(旧表中的 pk)将新记录插入到新表的标识列中。完成后运行 Set Identity_Insert Off 并关闭并运行。