Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do brackets mean around column names in SQL Server?

Tags:

I added a field in SQL Server 2008 and it put the column name in brackets like this: [column2]. The other column names don't have brackets. What do the brackets mean?

The column is named macro-writer

Should I remove the minus sign and replace it with an underscore?

like image 515
Alex Gordon Avatar asked Aug 23 '10 20:08

Alex Gordon


People also ask

What do brackets mean in SQL Server?

On SQL Server and MS Access, square brackets have a special meaning when used in a query filter. The square brackets are used to specify a set or range of characters, as in "[A-Z]" which would match any single character from 'A' to 'Z'.

Do brackets work in SQL?

Yes, the SQL standard allows parentheses.

When would you need to include square brackets around the name of a table within a select statement in SQL Server?

1) If you have SQL keyword, space or any other illegal characters then you need to use square brackets.


2 Answers

Brackets are a form of quoting. It's only necessary if the column name contains spaces or punctuation or conflicts with a reserved word, but many wizards will just add the brackets for all field names to avoid the logic for deciding whether they are necessary.

like image 187
Ben Voigt Avatar answered Sep 28 '22 02:09

Ben Voigt


Columns enclosed in square brackets are usually keywords or contain special characters or spaces.

What specific column name do you have enclosed in brackets?

like image 36
Bernard Avatar answered Sep 28 '22 02:09

Bernard