What is the use of the square brackets [] in sql statements?

I've seen that Visual Studio 2008 is positioning square brackets around column names in sql. Do the brackets supply any kind of benefit? When I hand code T - SQL I've never ever troubled with them.

Instance:

Visual Studio:

SELECT [column1], [column2] etc...

My very own means:

SELECT column1, column2 etc...
202
2022-06-08 20:16:12
Source Share
Answers: 6

The brackets can be made use of when column names are booked words.

If you are programatically creating the SQL declaration from a collection of column names you do not regulate, after that you can stay clear of troubles by constantly making use of the brackets.

6
2022-06-08 20:38:45
Source

Column names can have personalities and also booked words that will certainly perplex the query implementation engine, so positioning brackets around them in all times stops this from taking place. Less complicated than looking for a concern and afterwards managing it, I presume.

7
2022-06-08 20:38:45
Source

I think it includes them there for uniformity they are just called for when you have a room or unique personality in the column name, yet it is cleaner to simply include them regularly when the IDE creates SQL.

3
2022-06-08 20:38:41
Source

They come in handy if your columns have the very same names as SQL search phrases, or have rooms in them.

Instance:

create table test ( id int, user varchar(20) )

Oh no! Wrong syntax near the keyword 'customer'. Yet this:

create table test ( id int, [user] varchar(20) )

Works penalty.

72
2022-06-08 20:38:35
Source

They serve if you are (for one reason or another) making use of column names with particular personalities as an example.

Select First Name From People

would certainly not function, yet placing square brackets around the column name would certainly function

Select [First Name] From People

In brief, it is a means of clearly proclaiming a object name ; column, table, data source, customer or web server.

13
2022-06-08 20:38:31
Source

The brackets are called for if you make use of search phrases or unique chars in the column names or identifiers. You can call a column [First Name] (with a room)-- yet after that you would certainly require to make use of brackets every single time you described that column.

The more recent devices add them almost everywhere simply in instance or for uniformity.

221
2022-06-08 20:37:10
Source