all groups > sql server new users > march 2006 >
You're in the

sql server new users

group:

How to detect foreign key entries that would prevent deletion



How to detect foreign key entries that would prevent deletion keithb
3/27/2006 7:04:04 PM
sql server new users: Is there a query command that will detect whether or not a table row has any
foreign key entries that would prevent deletion?

Thanks,

Keith

Re: How to detect foreign key entries that would prevent deletion Tom Moreau
3/28/2006 12:00:00 AM
WHERE EXISTS is your friend:

select
*
from
MyTable m
where
-- put your search criteria here
and exists
(
select
*
from
OtherTable o
where
o.FK = m.PK
)

Use one EXISTS predicate per referencing table.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
[quoted text, click to view]
Is there a query command that will detect whether or not a table row has any
foreign key entries that would prevent deletion?

Thanks,

Keith

AddThis Social Bookmark Button