Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do square bracket appear with the table name?

I created a database with couple of tables and some table names are enclosed with square bracket: [table_name]

Does anyone know why this happens, and how to get rid of it?

like image 237
Niko Gamulin Avatar asked Mar 24 '09 01:03

Niko Gamulin


People also ask

What does [] mean in SQL query?

the brackets are special characters in sql server that are used to explicitly delimit information. they can be used in xml as per the article, they can also be used to specify meta names (column, table, etc.) that have spaces or other key words.

Why are square brackets used in SQL?

1) If you have SQL keyword, space or any other illegal characters then you need to use square brackets. 2) SQL server parse and compiler much more easy to validate and compile code. 3) code search tools easy to find table names or column names only.

How do you escape a bracket in SQL?

To escape square brackets in LIKE you can use another square bracket to escape the original square bracket or use a custom escape character using the ESCAPE keyword in LIKE clause.

What do parentheses mean in SQL?

Syntax, Examples, and Text Parentheses are used in SQL to group parameters or arguments. They are required when entering a command (i.e. they must be typed exactly as they appear). { item1 item2 ... } Curly braces indicate groupings of identifiers, parameters, or arguments.


2 Answers

When you use SQL Server Management Studio to script out your objects it will enclose all names with square brackets.

They are only necessary when the name contains a space or a reserved word (such as [Name]).

like image 91
Mitch Wheat Avatar answered Sep 19 '22 02:09

Mitch Wheat


Are the tables in question MSSQL keywords? It's a common notation to put MSSQL object names in brackets. It's no big deal.

like image 41
Samantha Branham Avatar answered Sep 21 '22 02:09

Samantha Branham