SQL server 2008 怎样根据从表中的一些条件删除主表中的某些元组
主表:Goods:

从表:Purchase:

从表Purchase中有如下语句:
PRIMARY KEY (Gno),
FOREIGN KEY (Gno) REFERENCES Goods(Gno)
删除所有Purchase中Num少于20个的商品信息,不包括Purchase中没有的商品(就是删除商品号Gno为1,2,5的)
------解决方案--------------------
这样呢,试试:
declare @temp table(gno varchar(30))
--先删除明细,会把删除的字段值,放到@temp表变量中
delete purchase
output deleted.gno into @temp
where num<20
--再删除主表
delete goods where Gno in (select Gno from @temp)