如何删除具有关系主键和外键的记录 [英] how to delete a record with an relation primary key and foreign key

查看:736
本文介绍了如何删除具有关系主键和外键的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海.........


这是极好的,请给我答案........


我有一个克里特岛的两个表,一个是表1,另一个是表2,它具有主键和外键,,我已经删除了表1中的一条记录,并且还通过关系自动删除了表2中的一条记录..... .


请在SQL Server中给我一个稳定的查询.......我在等待这个答案请回答我......

谢谢你
您的
pradeep

Hai.........


this is pradeep please give me answer please........


i have Crete a two table one is table1 and another is table2 this having relation primary key and foreign key ,,i have delete a record in table1 and also automatically delete a record in table2 by a relation please.........


give me a stable query in SQL server please..........i waiting for this answer please ans me ......

thanking you
yours
pradeep

推荐答案


转到两个表之间的关系,然后选择
Delete Rule设为Cascade
现在,如果您从主表中删除,它将从子表中删除.
另外,您还可以触发,最好的解决方案在一个过程上都可以使触发效果更好.

最好的问候
M.Mitwalli
Hi ,
Go to Relationship between the two tables then select
Delete Rule make it Cascade
now if you delete from the Main table it will delete from the sub table .
Also you can make trigger , the best Solution make both on one procedure it will be much better .

Best Regards
M.Mitwalli


嗨..

您需要删除具有外键的第二个表(table2)的记录,然后从具有主键的表1(table1)中删除记录.

热烈的问候

shivanand nagarabetta.
hi..

u need to delete the record of second table(table2) that has foreign key.and then delete the record from table one (table1) that has primary key.

Warm Regard

shivanand nagarabetta.


请在SQL Server中给我一个稳定的查询
不会.除非您知道它是什么以及它是如何完成的,否则对自己进行查询有什么意义?

我已经删除了表1中的一条记录,并且还自动删除了表2中的一条记录
阅读有关 SQL触发器 [
give me a stable query in SQL server please
No. Until unless you know what it is and how it''s done, whats the point of having a query with yourself?

i have delete a record in table1 and also automatically delete a record in table2
Read about SQL Triggers[^]. Once this is done, using your connection to SQL Server, execute the query/stored procedure that deletes something from table1. Internally, trigger will handle this event and delete a record in table2.

Try it and if you get stuck or face issues using it, do share across.


这篇关于如何删除具有关系主键和外键的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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