我只是想检查一些其他表中使用的外键 [英] i just want to check that foreign key used in some other table or not

查看:68
本文介绍了我只是想检查一些其他表中使用的外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用sql server 2008作为我的数据库引擎。我删除进程时更新[DeleteStatus]字段..但在这种情况下我面临删除进程的问题..我不想删除在其他一些表中使用外键时的行..记住,在这里我将[DeleteStatus]更新为true或false,而不是永久删除表..我只想检查其他表中使用的外键......哪种方式适合实现我的目标。请告诉我.......

I am using sql server 2008 as my data base engine. i update the [DeleteStatus] field when the time of deleting process.. but in this case i am facing an issue with delete process.. i dont want to delete the row when the foreign key is used in some other tables.. remember, here i am updating the [DeleteStatus] as true or false not to permanent deleting by the table..i just want to check that foreign key used in some other table or not.... which way is suitable for achieving my goal. let me know please.......

推荐答案

有多种方法可以知道该行是否有外键引用的子行。



赞,



There are various ways to know if the row has any child row refered by foreign key.

Like,

SELECT ColumnA,ColumnB FROM TableA 
WHERE NOT EXISTS 
(SELECT * FROM TableB WHERE TableB.id=TableA.id)



您还可以更新[DeleteStatus]列使用以上查询。



你也可以尝试


You can also update [DeleteStatus] column usign above query.

You can also try

SELECT ColumnA,ColumnB FROM TableA LEFT JOIN B ON TableA.id=TableB.id





希望有所帮助。

Milind



Hope that helps.
Milind


这篇关于我只是想检查一些其他表中使用的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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