4

When writing a query, can you separate schemas and objects with spaces and line feeds?

7

Yes, this is valid T-SQL:

SELECT
*
FROM
sys
.
databases
d
WHERE
d
.
name
=
'tempdb';

As is this:

SELECT * FROM sys . databases d WHERE d . name = 'tempdb';
GO

And they both work fine.

enter image description here

  • 1
    Although the T-SQL parser is lax, I'd stick with the documented syntax where there are no spaces separating the schema and object name. – Dan Guzman Apr 25 '18 at 0:18
  • @DanGuzman sure, but notice this was a "can you" question, not a best practices opinion question. ;-) – Brent Ozar Apr 25 '18 at 10:33
  • One can get away with this and many other syntax mistakes. Fortunately for many, Microsoft goes through great lengths to preserve T-SQL parser bugs :-) – Dan Guzman Apr 25 '18 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.