May 14, 2010 at 11:07 am
This was a good way to point out the risk of using reserved words within brackets as a user-defined object. While I would suppose few people would want to name a table "WHERE" as in the QOD, some other words like "Name" may be more attractive.
Alternatively, the use of brackets does offer the opportunity to have some fun...... (yes, this works).
create table [where]([Select from there] varchar(50))
insert into [where] values ('Careful with this')
select [from there].[Select from there] [from there] from [where] [from there]
May 14, 2010 at 11:11 am
john.arnott (5/14/2010)
This was a good way to point out the risk of using reserved words within brackets as a user-defined object. While I would suppose few people would want to name a table "WHERE" as in the QOD, some other words like "Name" may be more attractive.Alternatively, the use of brackets does offer the opportunity to have some fun...... (yes, this works).
create table [where]([Select from there] varchar(50))
insert into [where] values ('Careful with this')
select [from there].[Select from there] [from there] from [where] [from there]
How many people would be fooled by that chicanery?
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
May 14, 2010 at 11:11 am
CirquedeSQLeil (5/14/2010)
When using the AS to alias a Table, it makes it more clear to anybody coming after you to read what your intent was.
Thank you Jason.
That is why I assumed it wasn't aliasing because there was no AS.
This is why I do QotD, I alway learn something.
May 14, 2010 at 11:15 am
You're welcome.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
May 14, 2010 at 12:04 pm
CirquedeSQLeil (5/14/2010)
john.arnott (5/14/2010)
This was a good way to point out the risk of using reserved words within brackets as a user-defined object. While I would suppose few people would want to name a table "WHERE" as in the QOD, some other words like "Name" may be more attractive.Alternatively, the use of brackets does offer the opportunity to have some fun...... (yes, this works).
create table [where]([Select from there] varchar(50))
insert into [where] values ('Careful with this')
select [from there].[Select from there] [from there] from [where] [from there]
How many people would be fooled by that chicanery?
Cool, I just learned a new word, thank you Jason (chicanery - the use of clever but tricky talk or action to deceive or evade someone).
Oleg
May 14, 2010 at 12:43 pm
Oleg Netchaev (5/14/2010)
Nice question, thank you. It would be nice though if the database engine team would limit some of the square brackets allowances and throw sev 20 error. Something like:
Msg 8421, Level 20, State 1, Line 1
Abuse of the database engine encountered.
The connection has been forcibly closed by the server.
Oleg
I agree 100% with that. Allowing the sort of incredibley illegible nonsense that can arise out of this is one of SQLS's faults.
Although sev 20 maybe is a bit OTT - just kill the query rather than the connection, maybe?
Tom
May 14, 2010 at 1:24 pm
Oleg Netchaev (5/14/2010)
CirquedeSQLeil (5/14/2010)
john.arnott (5/14/2010)
This was a good way to point out the risk of using reserved words within brackets as a user-defined object. While I would suppose few people would want to name a table "WHERE" as in the QOD, some other words like "Name" may be more attractive.Alternatively, the use of brackets does offer the opportunity to have some fun...... (yes, this works).
create table [where]([Select from there] varchar(50))
insert into [where] values ('Careful with this')
select [from there].[Select from there] [from there] from [where] [from there]
How many people would be fooled by that chicanery?
Cool, I just learned a new word, thank you Jason (chicanery - the use of clever but tricky talk or action to deceive or evade someone).
Oleg
Woot :w00t:
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
May 16, 2010 at 9:47 pm
Good Example John
May 16, 2010 at 10:45 pm
Interesting and Good Question
Thanks 🙂
May 17, 2010 at 12:15 am
No You can't use it as [flag='y'].some_data, because you not give the table alias and fetching the column with reference to table alias, it can be work as select [flag='y'].some_data from [where] [flag='y']
May 18, 2010 at 12:12 am
Yes, u can use like that
Select [flag ='y'].some_data from [where] [flag ='y']
July 14, 2010 at 10:34 am
saranya.megalai (5/14/2010)
if flag is alias then can we use next statement likeselect [flag='y'].some_data from [where]?
actually:
Select [anything].some_data from [where] [anything]
December 22, 2010 at 4:07 am
Good question.
Regards,
Jagan.
November 22, 2011 at 1:18 am
Now this is a good question....:-D
From now on I will be more careful when using [] in my code...:w00t:
Thanks for something practical and not another trick question that hides something.
March 21, 2012 at 11:23 am
I like questions from which I learn
Igor Micev,My blog: www.igormicev.com
Viewing 15 posts - 31 through 44 (of 44 total)
You must be logged in to reply to this topic. Login to reply