Why does SQL Server Management Studio generate code using square brackets?

advertisements

When generating code/scripts,

  1. why does SQL Server Management Studio generate code using square brackets and not double-quotes?

    SELECT [NAME] FROM [TABLE]

  2. and is there a way (setting/registry entry) to configure it to use double-quotes (the standard) instead?

    SELECT "NAME" FROM "TABLE"

This is very MSFT-ty feature, given that all their documentation now indicate the double-quotes (see this)


why does sql-server (management studio) generate code using square brackets?

SELECT [NAME] FROM [TABLE]

To cope with the names that are reserved words or contain whitespaces.

Square brackets are the native way to wrap the identifiers to. They are asymmetrical and can be unmatched, while the quotes are symmetrical and should be matched (or doubled to include them into the name):

CREATE TABLE [[test] (id INT)
CREATE TABLE ["test] (id INT)
DROP TABLE "[test"
DROP TABLE """test"