I have a query with a subselect where I mistyped a column (id1 in the subselect). If the query is executed separatly SQL Server throws an error, which is correct and expected. However if executed as a subquery in the below context the typo is not catched - and in this case my table is cleared. Is this intented behaviour ?
CREATE TABLE #a1 (id1 INT);
CREATE TABLE #a2 (id2 INT);
INSERT INTO #a1 (id1) VALUES (1), (2), (3);
INSERT INTO #a2 (id2) VALUES (1);
DELETE FROM #a1 WHERE id1 = (SELECT id1 FROM #a2 WHERE id2 = 1);
SELECT * FROM #a1 -- wow, the table is now empty
I expected an error to be thrown, instead the delete query was interpreted as
DELETE FROM #a1 WHERE id1 = id1.