Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the space in this Where clause not cause a syntax error?

The below three Select queries, irrespective of the Where clause having an extra space between the table alias and the column name, produce the same result. They all have the same execution plans, too. Why does the presence of a space not throw a syntax error?

DECLARE @TblX TABLE(
    ColX int
    ,ColY float
    )

-----As it normally should be
SELECT *
FROM @TblX X
WHERE X.ColX = 1

----Even this works
SELECT *
FROM @TblX X
WHERE X .ColX = 1

----And this too
SELECT *
FROM @TblX X
WHERE X. ColX = 1
like image 717
anonxen Avatar asked Sep 15 '15 13:09

anonxen


1 Answers

Because SQL, while not entirely space-insensitive, is, let's say, "space-tolerant". For instance, try this one:

SELECT 23AB

Fun, huh? This feature came from way back in the original SQL specifications in the early 1980s when this kind of thing was still thought by some to be good (because Fortran and COBOL had similar behaviors). IIRC, it's deprecated now, but for legacy/compatibility reasons, we're still stuck with it.

like image 75
RBarryYoung Avatar answered Sep 30 '22 16:09

RBarryYoung