Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345»»

Careful with table name alias Expand / Collapse
Author
Message
Posted Friday, May 14, 2010 11:07 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, January 21, 2014 8:55 AM
Points: 1,520, Visits: 3,035
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]

Post #922200
Posted Friday, May 14, 2010 11:11 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 10:05 PM
Points: 20,485, Visits: 14,144
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


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #922203
Posted Friday, May 14, 2010 11:11 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: 2 days ago @ 11:26 AM
Points: 749, Visits: 1,137
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.
Post #922204
Posted Friday, May 14, 2010 11:15 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 10:05 PM
Points: 20,485, Visits: 14,144
You're welcome.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #922206
Posted Friday, May 14, 2010 12:04 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, April 21, 2014 10:01 AM
Points: 1,676, Visits: 1,745
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
Post #922234
Posted Friday, May 14, 2010 12:43 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 7:47 AM
Points: 8,296, Visits: 8,750
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
Post #922257
Posted Friday, May 14, 2010 1:24 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 10:05 PM
Points: 20,485, Visits: 14,144
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




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #922281
Posted Sunday, May 16, 2010 9:47 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 5:13 AM
Points: 1,128, Visits: 759
Good Example John
Post #922700
Posted Sunday, May 16, 2010 10:45 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, January 02, 2014 9:57 AM
Points: 554, Visits: 863
Interesting and Good Question
Thanks :)
Post #922708
Posted Monday, May 17, 2010 12:15 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, April 09, 2014 12:00 AM
Points: 33, Visits: 20
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']
Post #922713
« Prev Topic | Next Topic »

Add to briefcase «««12345»»

Permissions Expand / Collapse