Format SQL - valid but incorrect sql

KevinGreinerKevinGreiner Posts: 37 Bronze 3
edited July 8, 2015 3:06PM in SQL Prompt
I found a scenario today where Format SQL will change the SQL statement shown below into valid SQL that runs without error but is wrong. This is a dangerous error because the SQL is changed in a way that results in no UPDATE actually happening.
CREATE TABLE Cars (name VARCHAR(10)
                  ,wheels INT);

CREATE TABLE c (name VARCHAR(10));


UPDATE  r3
SET     r3.wheels = c.wheels
FROM    dbo.Cars r3
CROSS APPLY (SELECT wheels = 4) c;

The UPDATE is changed to
UPDATE  r3
SET     r3.wheels = r3.wheels
FROM    dbo.Cars r3
CROSS APPLY (SELECT wheels = 4) c;

Comments

Sign In or Register to comment.