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?
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.
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].
1) If you have SQL keyword, space or any other illegal characters then you need to use square brackets.
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 "...").
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With