views:

457

answers:

2

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)

+2  A: 

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"
Quassnoi
good point, I know that. I should change wording of my question: i meant why square bracket and not double quotes. will fix.
van
+2  A: 

Your link explains why, at least to me. The brackets are not setting-dependant, but the validity of " depends on the QUOTED_IDENTIFIER setting.

CodeByMoonlight