Very forgiving T-SQL parser behaviour

One of the thinks I like about working with SQL Server is that there's always something new to learn. Sometimes, as in this case it doesn't have much of a practical benefit. Whilst running a trace on a database application to troubleshoot why it wasn't working properly I noticed a query that looked a little odd. It had spaces between the user and object name in the from clause (it was a SQL 2000 instance hence user rather than schema) e.g. it had a query that looked something like the picture below

This parses and executes absoloutely fine so I wondered what would happen if I increased the amount of whitespace as shown below

Again this works fine and as demonstrated below you can even separate all the parts of the from clause across multiple lines.

As I said, not much practical use - I'm not sure how they even managed to end up writing an application that generate this T-SQL!

Published Saturday, January 17, 2009 5:03 PM by sqldbatips
Filed under:


Monday, January 19, 2009 12:10 PM by simonsabin

# re: Very forgiving T-SQL parser behaviour

This is one of the biggest pains for the team to extend TSQL and to implement intellisense.

Such loose requirements make it very difficult.

It gets worse with numbers and signage.