From the course: Querying Microsoft SQL Server 2019

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

When to use square brackets

When to use square brackets - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2019

Start my 1-month free trial

When to use square brackets

- [Instructor] When you right-click on a table name in the Management Studio Object Explorer window and choose Select Top 1000 Rows, you might've noticed that the query that's generated includes a lot of square brackets. Those brackets are included so that SQL Server can correctly interpret queries that reference table or column names that include spaces or special characters. None of the tables or columns in this database actually include spaces, but the automatically generated scripts include the square brackets anyway. To see how a query might fail if you omit the brackets when they're needed, I'm going to create a new simple query. Our table and query names don't include spaces so I can execute a query without any problems. However, if I try and add an alias that does includes spaces, for instance, I'll add an alias here to the FirstName column, I'll call it AS Person First Name. And we'll do the same thing to…

Contents