如何知道sql server数据库的外键&主键清单 [英] How to know sql server database foreignkey & primary key list

查看:147
本文介绍了如何知道sql server数据库的外键&主键清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


因为我需要知道数据库的外键和主键列表,因为我当时需要从database1插入到database2,所以我需要将外键,主键从database2删除,以便我可以插入数据库的之后,我需要重新创建密钥

注意:我得到了有关外键列表的查询,但是当我当时尝试删除外键时,出现主键引用错误

Hi ,
As i need to know the database Foreign keys & Primary keys list due to i need to insert from database1 to database2 at that time i need to drop the Foreign keys, Primary keys off the database2 so that i can insert the Data''s of database1 after that i need to recreate the keys

Note : i got the query for foreign keys list but when i try to drop Foreign keys at that time i getting primary key reference error

thanking you for your help soon!!

推荐答案

谁建议/要求您以这种方式进行迁移?您是否可以通过这种方式引入多少数据问题有任何想法?定义主键和外键是有原因的.我根本不建议您这样做.

而是尝试:
1.正确看一下数据库设计.按顺序创建表列表,其中最低的表具有最大的依赖性,最高的表是仅具有主键的主表的一种.
2.按从上到下的顺序填充/迁移表-首先是主表,然后是从属表.

这样,您将不需要删除任何密钥,并且数据被破坏的可能性最小.

我建议您与上级交谈,以获取更多指导,以防您需要更多帮助.
Who suggested/asked you to do the migration this way? Do you have any idea on how much data issues can be introduced this way? There was/is a reason why Primary key & Foreign keys are defined. I would not suggest you to do this way at all.

Instead try:
1. Have a look at the database design properly. make a list of tables in a sequence where the lowest tables having maximum dependencies and top once being kind of master table with only primary keys.
2. Populate/Migrate the table from top to bottom order - First the master tables and then the dependent tables.

This way you wont need to drop any key and the data would have least chance of getting corrupt.

I would suggest you to talk to your senior and get more guidance in case you need more help on the same.


这样做通常是一个坏主意 ,但有时您需要对大量插入内容执行此操作.

您可以禁用约束检查,请参见此处:
http://weblogs.sqlteam.com/joew/archive/2008/10/01/60719.aspx [ ^ ]
It is generally a bad idea to do this, but sometimes you need to do it for bulk inserts.

You can disable constraint checking, see here :
http://weblogs.sqlteam.com/joew/archive/2008/10/01/60719.aspx[^]


这篇关于如何知道sql server数据库的外键&主键清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆