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 |
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2007-03-21 : 11:14:58
|
| Hello,I have two tables with their columns as follows: LabelsInDocs [LabelId]PK, [DocsId]PK Labels [LabelId]PK, [LabelName] Docs [DocId]PK, [DocUrl]When I delete all records in LabelsInDocs given a DocId I need to:> Delete all records in Labels which LabelId is not present anymore in LabelsInDocs. Basically I need to delete all Labels which are not associated with any Doc anymore.How can I do this?Thanks,Miguel |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-21 : 11:24:38
|
| [code]Delete lfrom Labels l Left join LabelsInDocs don d.LabelId = l.LabelIdwhere l.LabelId is NULL[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
shapper
Constraint Violating Yak Guru
450 Posts |
Posted - 2007-03-21 : 13:48:09
|
| Harsh,If I use cascade delete, which means that if I delete a label or a doc all records in LabelsInDocs with given LabelId or DocId will be deleted, how can I "order" to delete all unused labels in Labels?Thanks,Miguel |
 |
|
|
|
|
|