简体   繁体   English

导出 SQL Server 数据库时没有 PK 或 FK

[英]No PK or FK when exporting SQL Server database

We have a Production and a Staging database hosted on Microsoft Azure.我们在 Microsoft Azure 上托管了一个生产数据库和一个临时数据库。 We're using Microsoft SQL Server Management Studio 19 to do the migrating.我们使用 Microsoft SQL Server Management Studio 19 进行迁移。

Here goes the steps下面是步骤

Right click the database -> Tasks -> Export Data...

We select SQL Server Native Client 11.0 as the Data Source.我们选择SQL Server Native Client 11.0作为数据源。

For authentication we select "Use SQL Server authentication" and type in our user name and password.对于身份验证,我们选择“使用 SQL Server 身份验证”并输入我们的用户名和密码。

In "Database", we select our Production database在“数据库”中,我们选择我们的生产数据库

After clicking Next, we'll now select our destination.单击下一步后,我们现在将选择我们的目的地。 For Destination we use "SQL Server Native Client 11.0" and the same setup as above, but just with our Staging database as destination.对于目标,我们使用“SQL Server Native Client 11.0”和与上述相同的设置,但只是使用我们的临时数据库作为目标。

Now it's time to "Specify Table Copy or Query" and here we select "Copy data from one or more tables or views".现在是“指定表复制或查询”的时候了,在这里我们选择“从一个或多个表或视图复制数据”。

We now mark all the tables and select Edit Mappings... , where we enable Enable identity insert .我们现在标记所有表并选择Edit Mappings... ,我们在其中启用Enable identity insert

If we then press Next and start the migration, everything seems to be completed without any errors or warnings.如果我们然后按 Next 并开始迁移,一切似乎都已完成,没有任何错误或警告。

BUT - For some reason all our PK and FK relations are not exported into our Staging database.但是- 由于某种原因,我们所有的 PK 和 FK 关系都没有导出到我们的 Staging 数据库中。

We have tried to look up a single table, just to see the SQL query which are generated and it looks like the image attached.我们试图查找单个表,只是为了查看生成的 SQL 查询,它看起来像附加的图像。

Can anyone tell us, what we're doing wrong.谁能告诉我们,我们做错了什么。 We have no idea, why the PK and FK's aren't migrated.我们不知道为什么不迁移 PK 和 FK。 Stored procedures and everything are working as expected.存储过程和一切都按预期工作。

在此处输入图片说明

There are two ways to export the PK and FK.两种方式可以导出PK和FK。

  1. Using SSMS to generate the sql script.使用 SSMS 生成 sql 脚本。 We just need to select the tables.我们只需要选择表格。 It will generate a script.sql in your local PC.它将在您的本地 PC 中生成一个 script.sql。

在此处输入图片说明

2 We can query System tables and views to splicing FK and PK's SQL statement. 2 可以通过查询System表和视图来拼接FK和PK的SQL语句。

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

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