What do the brackets do in a sql statement?
For example, in the statement:
insert into table1 ([columnname1], columnname2) values (val1, val2)
They allow you to use keywords (such as date) in the name of the column, table, etc...
Since this is a bad practice to begin with, they are generally not included. The only place you should see them being used is by people starting out with sql queries that don't know any better. Other than that they just clutter up your query.
This is Microsoft SQL Server nonstandard syntax for "delimited identifiers." SQL supports delimiters for identifiers to allow table names, column names, or other metadata objects to contain the following:
Microsoft SQL Server uses the square brackets, but this is not the syntax standard SQL uses for delimited identifiers. Standardly, double-quotes should be used for delimiters.
In Microsoft SQL Server, you can enable a mode to use standard double-quotes for delimiters as follows:
SET QUOTED_IDENTIFIER ON;
They are meant to escape reserved keywords or invalid column identifiers.
CREATE TABLE test
(
[select] varchar(15)
)
INSERT INTO test VALUES('abc')
SELECT [select] FROM test
Anything inside the brackets is considered a single identifier (e.g. [test machine]. This can be used to enclose names with spaces or to escape reserve words (e.g. [order], [select], [group]).
if you use any column name which is same as any reserved keyword in sql, in that case you can put the column name in square bracket to distinguish between your custom column name and existing reserved keyword.
They are simply delimiters that allow you to put special characters (like spaces) in the column or table name e.g.
insert into [Table One] ([Column Name 1], columnname2) values (val1, val2)