patternsqlModerate
Does it make sense to use SQL Server's bracket notation in hand written code?
Viewed 0 times
handwrittensqlmakebracketcodesensenotationdoesserver
Problem
Code generators tend to be simpler when they generate output using the new Microsoft bracket notation (
When I first saw it, I though wow a reincarnation of the somewhat banned quoted identifier notation.
As far as I know it is a proprietary extension from Microsoft (meaning Oracle doesn't support it).
Looking at SQL Server there is no difference if you define a table like
or
Its a matter of personal or corporate style. Be consistent.
Now if you want to migrate your database to Oracle, brackets are no option.
You can use the old quoted identifiers, but these are case sensitive which causes a lot of trouble.
Is it a good idea to remove all brackets from generated code, avoid using blanks, other special characters and reserved keywords for names and just code in a way that most DBMS understand?
[]) for nearly everything. When I first saw it, I though wow a reincarnation of the somewhat banned quoted identifier notation.
As far as I know it is a proprietary extension from Microsoft (meaning Oracle doesn't support it).
Looking at SQL Server there is no difference if you define a table like
CREATE TABLE [dbo].[Table_2] ([col1] [int], [col2] [int]);or
CREATE TABLE dbo.Table_2 (col1 int, col2 int);Its a matter of personal or corporate style. Be consistent.
Now if you want to migrate your database to Oracle, brackets are no option.
You can use the old quoted identifiers, but these are case sensitive which causes a lot of trouble.
Is it a good idea to remove all brackets from generated code, avoid using blanks, other special characters and reserved keywords for names and just code in a way that most DBMS understand?
Solution
Standard SQL uses the double quote
Needlessly using quoted identifiers, whatever the flavour, should be avoided, IMO.
" for quoted identifiers. SQL Server supports this using the QUOTED_IDENTIFIER option (ANSI_QUOTES in mySQL). Standard SQL improves portability in general and in this case would port to Oracle. Similarly I'd change SQL keywords to upper case (Intermediate SQL-92 requirement) and expand int to INTEGER (entry level SQL-92 requirement).Needlessly using quoted identifiers, whatever the flavour, should be avoided, IMO.
Context
StackExchange Database Administrators Q#280, answer score: 12
Revisions (0)
No revisions yet.