Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[] brackets in sql statements

Tags:

sql

ms-access

What do the brackets do in a sql statement?

For example, in the statement:

insert into table1 ([columnname1], columnname2) values (val1, val2)

Also, what does it do if the table name is in brackets?

like image 294
Adam Lerman Avatar asked Sep 30 '08 16:09

Adam Lerman


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.

What do brackets do in SQL Server?

Brackets allow you to delimit names in SQL Server. This allows you to do such things as use keywords [count] or include spaces [my column name].

Do you need square brackets in SQL?

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

What do curly brackets mean in SQL?

The clauses in an SQL statement that display between [brackets] are optional. If an optional clause has several components or keywords, they display within the brackets. Curly braces {} in SQL statements indicate that one or more clauses are used together. Ellipses are sets of periods (such as "...").


1 Answers

The [] marks the delimitation of a identifier, so if you have a column whose name contains spaces like Order Qty you need to enclose it with [] like:

select [Order qty] from [Client sales] 

They are also to escape reserved keywords used as identifiers

like image 180
albertein Avatar answered Oct 04 '22 02:10

albertein