From the course: Querying Microsoft SQL Server 2022
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
When to use square brackets - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2022
When to use square brackets
- [Instructor] When you right-click on any table name in the Management Studio Object Explorer window, and select top 1,000 rows, you might have 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 tables or column names that includes spaces. None of the tables or column names in this database actually do 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 simple query. So far so good. Our table and query names don't include space characters so the query runs without any issue. However, if I try and add aliases that do include spaces, for instance, we'll call this first name column as, person first name, and we'll call the last name column as, person…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.