简体   繁体   English

如果您打算删除表,是否必须单独删除外键/索引

[英]Is it mandatory to separately remove the foreign keys / indexes if you are planning to drop the table

Is it mandatory to separately remove the foreign keys / indexes, if you are planning to drop the table. 如果您打算删除表,是否必须单独删除外键/索引。 Since dropping the table seems to be removing foreign keys / indexes. 由于删除表似乎正在删除外键/索引。

I am using this gem http://github.com/matthuhiggins/foreigner to remove the create / remove foreign keys / indexes. 我正在使用这个宝石http://github.com/matthuhiggins/foreigner删除创建/删除外键/索引。 add_foreign_key seems to create foreign_key and an index. add_foreign_key似乎会创建foreign_key和一个索引。 Does that mean I should remove the index / foreign key separately on self.down OR can I just drop the table? 这是否意味着我应该在self.down上分别删除索引/外键,还是可以只删除表?

When you drop the table, everything goes. 当您放下桌子时,一切都会进行。 That is, the table and all dependent objects (indexes, constraints, triggers) are dropped in one go. 也就是说,表和所有相关对象(索引,约束,触发器)都将被一次性删除。

Note that the drop will fail if other objects that depends on this table (such as schema bound views, the "1" side in an FK etc) 请注意,如果依赖此表的其他对象(例如架构绑定视图,FK中的“ 1”侧等),则放置将失败

No. It just drops everything and works - including FK that refer to other tables. 不会。它只是删除所有内容并起作用-包括引用其他表的FK。

It will fail if there are other tables with FK refering to this table, of course. 当然,如果还有其他带有FK的表引用该表,则它将失败。
But that is a different matter. 但这是另一回事。

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

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