When generating code/scripts,
why does SQL Server Management Studio generate code using square brackets and not double-quotes?
SELECT [NAME] FROM [TABLE]
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)
On SQL Server and MS Access, square brackets have a special meaning when used in a query filter. The square brackets are used to specify a set or range of characters, as in "[A-Z]" which would match any single character from 'A' to 'Z'.
Using brackets allows your code to be upgraded to a new SQL Server version, without first needing to edit Microsoft's newly reserved words out of your client code.
1) If you have SQL keyword, space or any other illegal characters then you need to use square brackets. 2) SQL server parse and compiler much more easy to validate and compile code. 3) code search tools easy to find table names or column names only.
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"
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