Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 314
van Avatar asked Oct 09 '09 14:10

van


People also ask

Why does SQL Server use square brackets?

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'.

Why do we use [] in SQL?

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.

Do you need square brackets in SQL?

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.


1 Answers

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"
like image 91
Quassnoi Avatar answered Nov 04 '22 02:11

Quassnoi