Thursday, March 8, 2012

'[object name]' - what is the purpose of '' in t-sql?

[] is SQL Server specific. ANSI SQL is to delimit identifiers using double-q
uotes. SQL Server
supports the later as well, which is what I prefer, but rest of SQL Server c
ommunity seems to
disagree with me.
I find code using delimiters *much* harder to read, so follow the rules for
"standard identifiers"
when you create your objects, and you can skip these types of delimiters and
laugh at those poor
souls who need to maintain code that uses delimiters.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Dan" <nobody@.nospam.com> wrote in message news:O0CcexwjGHA.5036@.TK2MSFTNGP04.phx.gbl...[co
lor=darkred]
> Hi,
> It's got to be a simple question. I'm about to write a relatively simple
queries to manipulate
> data in a MS SQL database. I've got some experience with DB/2 and MySQL.
I've been going through
> some samples/tutorials and noticed that object names are quite often surro
unded by '[]'.
> Could someone please explain the purpose of square brackets surrounding ab
ject names as in the
> below example?
> I think that they are not really needed in this particular example (used f
or illustration purposes
> only?). Still, I'd like to know what their purpose in t-sql is (outside o
f multi-dimensional
> queries)?
> Thanks,
> Dan
> use AdventureWorksDW
> GO
> SELECT
> FirstName as 'First'
> , [MiddleName] as 'Middle'
> , [LastName] as 'Last'
> , [Title]
> FROM [AdventureWorksDW].[dbo].[DimEmployee] as AWD
> WHERE AWD.MiddleName like 'B'
> Order by LastName Asc
> GO
>[/color]As I undestand the ANSI standard, quoted identifiers are supposed to be case
sensitive as well, so that "ColumnA" would not be the same as "columna". In
SQL Server they're not case sensitive (unless you are using a case-sensitive
collation I believe).
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:ezKuK24jGHA.3780@.TK2MSFTNGP03.phx.gbl...
> [] is SQL Server specific. ANSI SQL is to delimit identifiers using
> double-quotes. SQL Server supports the later as well, which is what I
> prefer, but rest of SQL Server community seems to disagree with me.
> I find code using delimiters *much* harder to read, so follow the rules
> for "standard identifiers" when you create your objects, and you can skip
> these types of delimiters and laugh at those poor souls who need to
> maintain code that uses delimiters.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Dan" <nobody@.nospam.com> wrote in message
> news:O0CcexwjGHA.5036@.TK2MSFTNGP04.phx.gbl...
>

No comments:

Post a Comment