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 |
Zath
Constraint Violating Yak Guru
298 Posts |
Posted - 2009-08-06 : 15:43:38
|
Trying to avoid a cursor to do this, so posting the question here.For each PK id in tbl1, a field in tbl2 needs to be checked.If the PK in tbl1 does NOT exist in tbl2Then delete that record in tbl1Like I said, could use a cursor for this but I know there's a better way.Thanks,Zath |
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-08-06 : 16:03:06
|
[code]delete A from tbl1 A LEFT JOIN tbl2 B on A.PK = B.PK where B.PK is NULL[/code] |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-08-06 : 16:37:04
|
delete A from tbl1 A where not exists(select * from tbl2 where PK=A.PK) |
|
|
|
|
|