Table/column names enclosed in square brackets, even though their names consist of legal characters

Posted by AspOnMyNet on Stack Overflow See other posts from Stack Overflow or by AspOnMyNet
Published on 2010-05-22T18:53:40Z Indexed on 2010/05/22 19:00 UTC
Read the original article Hit count: 302

Filed under:
|
|

Square brackets allow you to use names for columns or aliases that contain characters not permitted for column names or aliases.

a) I’ve noticed that lots of times table and column names are enclosed inside square brackets, even though their names consist of perfectly legal characters. Why is that?

b) As far as I know, square brackets enclosing object’s name aren’t actually a part of that name. Thus, if we create a table named [A]:

CREATE TABLE [A] ( … )

we can later reference it without using brackets:

SELECT * FROM A

But why isn’t the same true when I try to reference a column KEY from a table returned by CONTAINSTABLE function? Namely, if I omit the brackets enclosing column name, I get an error:

SELECT ct.KEY   
FROM CONTAINSTABLE(fullText,*,'some_string') as ct

thanx

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server