我想这样做:如何删除相互引用的表中的行?
delete from table1 a,table2 b, table3 c
where a.col1 = b.col1
and b.col2 = c.col2
and a.co3 <> 8001;
但它给我的错误。
我想这样做:如何删除相互引用的表中的行?
delete from table1 a,table2 b, table3 c
where a.col1 = b.col1
and b.col2 = c.col2
and a.co3 <> 8001;
但它给我的错误。
先删除的最低水平,并从那里向上移动,一个每一级删除,为最高级别:
DELETE FROM ChildTable WHERE ParentID=...
DELECT FROM ParentTable WHERE ParentID=...
+1:SQL Server不支持多表删除 – 2010-03-09 15:40:24
实际上,您可以使用thekaido提到的级联函数来实现此功能 – super9 2010-03-09 15:45:47
既然你没有指定什么每个表都有一个外键和在其领域,我会猜测:
Delete TableC
Where Exists(Select 1 From TableA Where TableA.Col1 = TableC.Col2 And TableA.Col3 <> '8001')
Delete TableB
Where Exists(Select 1 From TableA Where TableA.Col1 = TableB.Col2 And TableA.Col3 <> '8001')
Delete TableA
Where Col3 <> '8001'
从表1一个删除A,表2 B,表3Ç
其中a.col1 = b.col1
和b.col2 = c.col2
和a.co3 <> 8001;
什么是错误(以及你想要发生什么) – Mark 2010-03-09 15:36:15
模式是什么样的?哪些表具有外键? – Thomas 2010-03-09 15:36:44
a.col1主键 b.col1 forien键,主键 c.col2 foriend关键 – SmartestVEGA 2010-03-09 15:38:25