SQL syntax

  • They may all work, but they are all a crime against readability. I make a point of white space for readability just about everywhere.

  • "A crime against readability" I'll reuse that quote soon enough.

  • I'm afraid I have to join the chorus in saying the question was poorly worded.

    Interesting info though.

    Tom Garth
    Vertical Solutions[/url]

    "There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
  • malleswarareddy_m (5/27/2010)


    I did not understand this question.in question it shows that to select wrong sytax.but all resturns table data without any error.then i did not found the wrong answer.so i applied three answers.got my point.

    He did say "select all that apply"

    So 1st you have to select all the statements that are correct, then guess the error statements?

    The part about guessing the error messages, if there are any, are for extra credit:-D

    Ken

  • All are correct

  • I have removed the sentence about error messages since it was confusing.

  • I'd have liked to see a 4th option, "none of the above". I believe that would have added to the educational opportunity.

    But then, why pose this question at all? Doesn't it promote harder to read code, and the memorization of what is essentially trivia?

    select * from table_name

    I'd argue that the above statement is: easier to read, doesn't require knowledge of this trivia, works if you substitue "my_column" for the "*", and is probably far more cross platform compatible.

    These are meant as constructive criticisms. I do very much appreciate the learning opportunity!

  • thanks for the Question

    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

  • In testing out the theory (not pasting from the examples which inherently include a space before the table name)... only the second query runs without error:

    --WON'T RUN: select*fromUDM.DimDate --'no space between select, *, and from

    select* from UDM.UDM.DimDate -- 'no space between select and *

    --WON'T RUN: select *fromUDM.DimDate-- 'no space between * and from

    I ran this against 2005 SQL Server via Management Studio.

  • Gotcha! The spacing between Select*from doesn't matter but there must be a space after from for the table name.... THanks for the learning!

  • I personally didn't find the question confusing. And, although the syntax definitely is NOT advisable for readability, etc. it is interesting to know how SSMS will parse some code without the white space.

    Thanks for the question.

  • I would argue that while all three compile and run, none of them is "correct." If they were correct, then so would this be, and you know it's not:

    SELECTmycolumnFROM MyTable;

    SELECTmycolumn FROM MyTable;

    SELECT mycolumnFROM MyTable;

    However, I'd leave the question alone. It was interesting to see weirdness in the parser.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey (5/28/2010)


    I would argue that while all three compile and run, none of them is "correct."

    In the same way that 2+2=5 for sufficiently large values of 2? 😛

  • Nice (but quite shocking!) question. I'm not at all embarrassed to say I got this one wrong.

  • For me all three options worked. I am using SQL 2008 express edition .

Viewing 15 posts - 16 through 30 (of 37 total)

You must be logged in to reply to this topic. Login to reply