使用外键和拓扑排序创建/删除表... [英] Creating/Dropping Tables with Foreign Keys and Topological Sort...

查看:91
本文介绍了使用外键和拓扑排序创建/删除表...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试应用程序正在创建的表,当然,表之间存在外键关系.当然存在一些限制...具有外键的表必须在其原始表中存在外键列之后创建,并且当然...您不能删除其他列为外键的表.因此,创建和删除问题.在表结构上实现拓扑排序似乎是一个经典案例(当然,假设设计中没有循环依赖性...).有没有一种方法可以创建或删除所有不进行排序的表,除了当然实际上是手动实现拓扑排序并选择有效的创建顺序外?

Hey, I''m trying to the tables that my application is creating, and of course there are foreign key relations between tables. There are of course some limitations... Tables that have foreign key must be created after the foreign key column exists in its original table, and of course... you can''t delete a table whose column is a foreign key somewhere else. So the creating and dropping problem. It seems like a classic case to implement a topological sort on the table structure (of course, assuming that there are no circular dependencies in the design...). Is there a way to create or drop all tables without the sort, except for of course actually implementing the topological sort manually, and choosing a valid creation sequence?

推荐答案

请参见这个,如果它可以帮助您

http://decipherinfosys.wordpress.com /2008/02/20/disableenable-foreign-key-and-check-constraints-in-sql-server/ [
See this, if it can help you

http://decipherinfosys.wordpress.com/2008/02/20/disableenable-foreign-key-and-check-constraints-in-sql-server/[^]


您可以禁用约束检查并执行所需的操作.

参见:
http://stackoverflow.com/questions/159038/can-foreign-key-constraints-be-tempablely-disabled-using-t-sql [
You can disable the constraint check and do what ever you want.

See :
http://stackoverflow.com/questions/159038/can-foreign-key-constraints-be-temporarily-disabled-using-t-sql[^]


这篇关于使用外键和拓扑排序创建/删除表...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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