Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Jouni79
Starting Member
9 Posts |
Posted - 2009-03-10 : 03:35:56
|
Hello everyone.I hope I put this in right area. I want to ask your opinion. How to check is foreign key in use .Now when try to delete record witch have reference to other table. now I get The DELETE statement conflicted with the REFERENCE constraint. I want to just check if foreign key is in use. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-10 : 04:20:14
|
just check the table in which fk is referenced using IF NOT EXISTSIF NOT EXISTS(SELECT 1 FROM ChildTable WHERE fk= yourvalue)DELETE m FROM Master m WHERE m.pk=yourvalue or if you want to do all of deletes in batch then useDELETE mFROM Master mLEFT JOIN Child cON c.fk=m.pkWHERE c.fk IS NULL |
 |
|
Jouni79
Starting Member
9 Posts |
Posted - 2009-03-11 : 03:13:32
|
Thank you.That helped me. |
 |
|
|
|
|