级联删除 [英] Cascading to delete

查看:80
本文介绍了级联删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个新数据库,
实体表包含[ID(主键),名称,日期,标识(主键)].
子表如下,
1.状态[StateID(带有实体表的主键和外键),Identity(带有实体表的外键)]
2.城市[CityID(带有实体表的主键和外键),标识(带有实体表的外键)]
3. Street [StreetID(具有实体表的主键和外键),标识(具有实体表的外键)]

如果我想删除实体表中的特定ID,它也应该在整个子表中删除.对我而言,实体表包含更多数量的外键,因此我无法使用级联功能.是否,同时使用较多数量的主键和外键影响表.我们可以创建级联选项吗?可能是什么原因?





我有1个主表和5个子表,其中的每个子表都被赋予了"CASCADE"的删除功能.如果我将所有的子表连接到主表,并且只有1个"CASCADE"仅允许.请给我一个解决方案,以给出多个级联

Hi,

I developing a new database,
The entity table contains [ID(Primary Key), Name, Date, Identity(Primary Key)].
The Child Tables as follows,
1. State [StateID(Primary Key & Foreign Key with Entity Table), Identity(Foreign Key with Entity Table)]
2. City [CityID(Primary Key & Foreign Key with Entity Table), Identity(Foreign Key with Entity Table)]
3. Street[StreetID(Primary Key & Foreign Key with Entity Table), Identity(Foreign Key with Entity Table)]

If i want to delete a particular ID in entity table, it should delete in entire child tables too. For me, The Entity Table contains more number of foreign key, so i can''t able to use cascading function. Whether, while using more number of primary key and foreign key affected in the table. We can able to create an option of cascading? What may be the reason?





I having 1 Master Table and 5 Child table, the every child table among them and i gave "CASCADE" for delete function. If i connect all the child table to master table, and only 1 "CASCADE" only allowing. Kindly give me a solution to give more than one cascade

推荐答案

不太了解您的问题.单个表不能具有多个主键.主键可以是复合键,但不会使外键约束不可用.

如果有复合键是问题,只需定义主键所需的所有列.但是,基于字段名称,它们看起来并不像是合成的.
Don''t quite understand your question. A single table cannot have multiple primary keys. A primary key can be a composite key but that won''t make foreign key constraints unusable.

If having a composite key is the problem, just define all the columns necessary to the primary key. However based on the field names they don''t look like they would be composite.




您正在使用引用,当您定义外键时,需要设置一个属性,即级联删除,将其设置为true.您的问题将得到解决.
Hi,

You are using referencing, when you define foreign key then there there is one property to be set, cascading deletion, set it to true. Your problem will be solve.




在您的方案中,也可以级联删除.如果您无法执行此操作,则可以使用其他解决方法,

1)使您对表的所有操作都应通过存储过程进行.
2)不允许直接访问表.
3)在存储过程中创建事务
4)在子表的事务调用删除操作中.

但仅当您无法在外键上创建级联删除时,才使用上述方案.

希望这对您有帮助,

谢谢
-amit.
Hi,

Cascading delete is possible in your scenario as well. if you are not able to do that then there can be other workaround,

1) Make your all operation on table should be through Stored procedure.
2) do not allow direct access to table.
3) create transaction inside stored procedure
4) within transaction call delete operation for your child table.

but use above scenario only if you are unable to create cascade delete on your foreign key.

Hope this will help you,

thanks
-amit.


这篇关于级联删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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