﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Roshan  Joseph  / Careful with table name alias / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 02:57:28 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>I like questions from which I learn</description><pubDate>Wed, 21 Mar 2012 11:23:52 GMT</pubDate><dc:creator>IgorMi</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Now this is a good question....:-DFrom 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.</description><pubDate>Tue, 22 Nov 2011 01:18:09 GMT</pubDate><dc:creator>terrykzncs</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Good question.</description><pubDate>Wed, 22 Dec 2010 04:07:58 GMT</pubDate><dc:creator>jaganmohan.rao</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]saranya.megalai (5/14/2010)[/b][hr]if flag is alias then can we use next statement like select [flag='y'].some_data from [where]?[/quote]actually:Select [anything].some_data from [where] [anything]</description><pubDate>Wed, 14 Jul 2010 10:34:07 GMT</pubDate><dc:creator>forjonathanwilson</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Yes, u can use like thatSelect [flag ='y'].some_data from [where] [flag ='y']</description><pubDate>Tue, 18 May 2010 00:12:49 GMT</pubDate><dc:creator>anil.sharma 8548</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>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']</description><pubDate>Mon, 17 May 2010 00:15:36 GMT</pubDate><dc:creator>ADY</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Interesting and Good QuestionThanks :)</description><pubDate>Sun, 16 May 2010 22:45:30 GMT</pubDate><dc:creator>deepak.a</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Good Example John</description><pubDate>Sun, 16 May 2010 21:47:59 GMT</pubDate><dc:creator>sharath.chalamgari</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]Oleg Netchaev (5/14/2010)[/b][hr][quote][b]CirquedeSQLeil (5/14/2010)[/b][hr][quote][b]john.arnott (5/14/2010)[/b][hr]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).[code="sql"]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][/code][/quote]How many people would be fooled by that chicanery?[/quote]Cool, I just learned a new word, thank you Jason ([b]chicanery[/b] - the use of clever but tricky talk or action to deceive or evade someone).Oleg[/quote]Woot :w00t:</description><pubDate>Fri, 14 May 2010 13:24:01 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]Oleg Netchaev (5/14/2010)[/b][hr]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:[code="plain"]Msg 8421, Level 20, State 1, Line 1Abuse of the database engine encountered. The connection has been forcibly closed by the server.[/code]Oleg[/quote]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?</description><pubDate>Fri, 14 May 2010 12:43:57 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]CirquedeSQLeil (5/14/2010)[/b][hr][quote][b]john.arnott (5/14/2010)[/b][hr]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).[code="sql"]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][/code][/quote]How many people would be fooled by that chicanery?[/quote]Cool, I just learned a new word, thank you Jason ([b]chicanery[/b] - the use of clever but tricky talk or action to deceive or evade someone).Oleg</description><pubDate>Fri, 14 May 2010 12:04:35 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>You're welcome.</description><pubDate>Fri, 14 May 2010 11:15:03 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]CirquedeSQLeil (5/14/2010)[/b][hr]When using the AS to alias a Table, it makes it more clear to anybody coming after you to read what your intent was.[/quote]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.</description><pubDate>Fri, 14 May 2010 11:11:52 GMT</pubDate><dc:creator>jlennartz</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]john.arnott (5/14/2010)[/b][hr]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).[code="sql"]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][/code][/quote]How many people would be fooled by that chicanery?</description><pubDate>Fri, 14 May 2010 11:11:42 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>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).[code="sql"]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][/code]</description><pubDate>Fri, 14 May 2010 11:07:06 GMT</pubDate><dc:creator>john.arnott</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>When using the AS to alias a Table, it makes it more clear to anybody coming after you to read what your intent was.</description><pubDate>Fri, 14 May 2010 11:05:48 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>So if you can alias without use of the AS clause why have it?</description><pubDate>Fri, 14 May 2010 11:03:43 GMT</pubDate><dc:creator>jlennartz</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Very interesting question! The alias name puzzled me for a while.</description><pubDate>Fri, 14 May 2010 11:02:08 GMT</pubDate><dc:creator>AmolNaik</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Thanks for the question.  Very creative, I would never have thought to write a question like this.</description><pubDate>Fri, 14 May 2010 09:54:23 GMT</pubDate><dc:creator>Trey Staker</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>I think this was a good question, but the title "Careful with table name alias" sort of gave everything away.</description><pubDate>Fri, 14 May 2010 09:45:38 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>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:[code="plain"]Msg 8421, Level 20, State 1, Line 1Abuse of the database engine encountered. The connection has been forcibly closed by the server.[/code]Oleg</description><pubDate>Fri, 14 May 2010 09:06:39 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Aside from the minor case correction of 'Careful with' that several astute observers noticed, this is a great question. It's even possible it will help in diagnosing something crazy like that showing up in legacy code. I know I have lots of room for improvement, but I would never actually write aliases like that or use [where] as a table name. But it is important to know that with the brackets, such statements would work.And I got the question right, to boot!Thanks,webrunner</description><pubDate>Fri, 14 May 2010 08:51:28 GMT</pubDate><dc:creator>webrunner</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>The correct is 'Careful with ' not 'careful with '</description><pubDate>Fri, 14 May 2010 08:29:42 GMT</pubDate><dc:creator>Geraldo Dominguez-450858</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]hmi (5/14/2010)[/b][hr]Creative statement good for braintraining but with a high theoretical fineness.Not any SQL developer with some common sense would name a table [where] nor would invent the alias [flag ='y' ][/quote]I've seen stranger things.;-)</description><pubDate>Fri, 14 May 2010 08:15:57 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]Richard M. (5/14/2010)[/b][hr]Nice one.... also good to use as an interview question :-D[/quote]Good point. Adding to the list of interview questions!</description><pubDate>Fri, 14 May 2010 07:49:04 GMT</pubDate><dc:creator>dunnjoe</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>I love it!  This ranks right up there with the Middle Join QOD, which is one of my all time favorites.  I think someone actually tried to write a SQL Statement once that read as a poem using carefully named tables and a ton of table and column aliases, but I don't remember where I saw that now.This is great, nicely done Roshan!Chad</description><pubDate>Fri, 14 May 2010 07:46:10 GMT</pubDate><dc:creator> Chad Crawford</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Nice one.... also good to use as an interview question :-D</description><pubDate>Fri, 14 May 2010 07:32:37 GMT</pubDate><dc:creator>Richard M.</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>When I actually realized that [quote][flag ='y' ][/quote] was an alias....I actually laughed.  This is a situation so unlikely that it is humorous, but it teaches a good lesson.  Great question for a Friday. Thanks.</description><pubDate>Fri, 14 May 2010 07:05:59 GMT</pubDate><dc:creator>Daniel Bowlin</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>There is nothing special about flag='y'... it's text.  It could be anything He's just aliasing the table.The point is that by using square brackets you can alias something to even something crazy that looks like an expression.[code]--These are all the same...Select * from [where] [flag ='y' ]Select * from [where] [Beer]Select [flag ='y' ].* from [where] [flag ='y' ]Select [Beer].* from [where] [Beer]Select table1.some_data from [where] table1[/code]</description><pubDate>Fri, 14 May 2010 06:50:41 GMT</pubDate><dc:creator>nycdotnet</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Creative statement good for braintraining but with a high theoretical fineness.Not any SQL developer with some common sense would name a table [where] nor would invent the alias [flag ='y' ]</description><pubDate>Fri, 14 May 2010 06:46:59 GMT</pubDate><dc:creator>hmi</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]saranya.megalai (5/14/2010)[/b][hr]if flag is alias then can we use next statement like select [flag='y'].some_data from [where]?[/quote]Yes it would look like:[code="plain"]Select [flag ='y' ].some_data from [where] [flag ='y' ][/code]</description><pubDate>Fri, 14 May 2010 06:04:43 GMT</pubDate><dc:creator>DaveD-128295</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Interesting question, it was the alias that almost caught me out. Have seen plenty of attributes named as reserved words in the past which has caused a few issues unless squared brackets were used. Thinking back I had an interview question once where there was a table called ORDER and the question was what would happen.</description><pubDate>Fri, 14 May 2010 05:04:46 GMT</pubDate><dc:creator>RichardDouglas</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Really its a good question about square brackets.we can use square brackets efficiently at any time.</description><pubDate>Fri, 14 May 2010 04:56:24 GMT</pubDate><dc:creator>malleswarareddy_m</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Really interesting and good question. :Wow:</description><pubDate>Fri, 14 May 2010 04:27:34 GMT</pubDate><dc:creator>Kari Suresh</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>[quote][b]saranya.megalai (5/14/2010)[/b][hr]if flag is alias then can we use next statement like select [flag='y'].some_data from [where]?[/quote]No :-)I haven't tested it, but the following should work:[code="sql"]select [flag='y'].some_data from [where] [flag='y'][/code]</description><pubDate>Fri, 14 May 2010 03:10:38 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>if flag is alias then can we use next statement like select [flag='y'].some_data from [where]?</description><pubDate>Fri, 14 May 2010 02:58:57 GMT</pubDate><dc:creator>saranya.megalai</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>I learnt another thing, thanks to the Question of the day. :-)</description><pubDate>Fri, 14 May 2010 02:48:20 GMT</pubDate><dc:creator>Kratos</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>Really good question, create confusion in mind for the "=" sign used in alias.</description><pubDate>Fri, 14 May 2010 01:11:56 GMT</pubDate><dc:creator>keyur.patel</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>fine, but correct is 'Careful with '(no rtrim and lower used)</description><pubDate>Fri, 14 May 2010 00:45:48 GMT</pubDate><dc:creator>Th. Fuchs</dc:creator></item><item><title>RE: Careful with table name alias</title><link>http://www.sqlservercentral.com/Forums/Topic921732-1557-1.aspx</link><description>very interesting, this table alias in select clause got me puzzled for a moment. :)</description><pubDate>Fri, 14 May 2010 00:04:45 GMT</pubDate><dc:creator>muhammad.mazhar</dc:creator></item></channel></rss>