[] brackets in sql statements

前端 未结 8 2432
深忆病人
深忆病人 2020-11-28 12:24

What do the brackets do in a sql statement?

For example, in the statement:

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

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 13:01

    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:

    • SQL reserved words: "Order"
    • Words containing spaces: "Order qty"
    • Words containing punctuation: "Order-qty"
    • Words containing international characters
    • Column names that are case-sensitive: "Order" vs. "order"

    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;
    

提交回复
热议问题