我有这个查询...我需要将其更改为TSQL支持的语句...我相信我需要更改为不存在的位置...但我还需要3个删除语句(每个表删除一次) ?)
DELETE DISTINCTROW TABLE1.*, TABLE2.column1, TABLE3.column2
FROM (
TABLE1 LEFT JOIN TABLE2 ON (TABLE1.column3 = TABLE2.column3)
AND (TABLE1.column1 = TABLE2.column1)
)
LEFT JOIN TABLE3 ON (TABLE1.column3 = TABLE3.column3)
AND (TABLE1.column1 = TABLE3.column2)
WHERE (
((TABLE2.column1) IS NULL)
AND ((TABLE3.column2) IS NULL)
);
答案 0 :(得分:0)
如果我正确理解了这个问题,你可以通过使用select获取每个表的键值来实现。然后使用3个删除语句
DECLARE @RecIds AS TABLE (sTableName VARCHAR(100), recidTableXRecord INT)
INSERT INTO @RecIds (recidTable1 , recidTableXRecord)
SELECT 'Table1', <Unique Record Id for table 1>
FROM .... ( ) AS TableRecords1
INSERT INTO @RecIds (recidTable2 , recidTableXRecord)
SELECT 'Table2', <Unique Record Id for table 1>
FROM .... ( ) AS TableRecords1
INSERT INTO @RecIds (recidTable3 , recidTableXRecord)
SELECT 'Table3', <Unique Record Id for table 1>
FROM .... ( ) AS TableRecords1
...然后删除
DELETE FROM TABLE1 WHERE recidTable1 IN (SELECT recidTableXRecord FROM @RecIds WHERE sTableName ='TABLE1')
DELETE FROM TABLE2 WHERE recidTable1 IN (SELECT recidTableXRecord FROM @RecIds WHERE sTableName ='TABLE2')
DELETE FROM TABLE3 WHERE recidTable1 IN (SELECT recidTableXRecord FROM @RecIds WHERE sTableName ='TABLE3')
......可能有更好的方法,但这会起作用并且易于维护。 建议把所有事情都放在交易中。