一次从多个表中删除. [英] deleting from multiple tables at a time .

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

问题描述

你好朋友.
我在sqlserver中有问题.
我想从三个表中删除数据
基于employeecontactinfo中的profileid和status列的employeecontactinfo,empeduinfo,empworkinfo.
现在profileid是employeecontactinfo表中的主键,而其余两个表中的foriegn键.
我该怎么办.

hello friends .
i have a problum in sqlserver.
i want to delete data from three tables
employeecontactinfo,empeduinfo,empworkinfo on the basis of profileid and status column in employeecontactinfo.
now profileid is primary key in employeecontactinfo table and foriegn key in remaining two tables.
how can i do it .
thanks in advance.

推荐答案

您当然也可以使用CASCADE ON DELETE.引用您要删除的条目的其他表的所有记录也将被删除.在此处阅读有关此内容的信息: http://www.sqlservercentral.com/Forums/Topic496734-149-1. aspx [ ^ ]或此处: http://msdn.microsoft.com/en-us/library/ms188066.aspx [< ^ ].

最好的问候,

-MRB
You can of course also use CASCADE ON DELETE. Any records of other tables that reference the entry you are deleting will also be deleted. Read some about it here: http://www.sqlservercentral.com/Forums/Topic496734-149-1.aspx[^] or here: http://msdn.microsoft.com/en-us/library/ms188066.aspx[^].

Best Regards,

-MRB


首先,我不建议物理删除,请按逻辑删除.

您可以编写3个查询来删除数据或更改某些逻辑字段的状态.
First of all I will not suggest for physical delete, delete logically.

You can write 3 queries to delete the data / or change the status of some logical field.


现在profileid是employeecontactinfo表中的主键,而其余两个表中的foriegn键. /i>
由于FK关系,您需要从 employeecontactinfo 删除行之前,先从 empeduinfo empworkinfo 中删除行.

删除引用的行后,您可以从第三张表中删除.一个简单的DELETE查询应该可以为您完成.
now profileid is primary key in employeecontactinfo table and foriegn key in remaining two tables.
You need to delete the rows from empeduinfo,empworkinfo before deleting the row from employeecontactinfo - because of FK relation.

Once you remove the referenced rows you can remove from the third table. A simple DELETE queries should do for you.


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

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