Create Procedure

  • paul 25096 (11/4/2015)


    I think the reason "Options 1, 2 and 3" has more votes than "Option 2" is because of course you should also avoid statements that cause a syntax error. The question could have been clearer!

    +1

  • Ooooh, the sneakiest question in a long while - should/cannot - definitely open to interpretation. Like all dodgy questions, people may still learn from it, but I think it's better that the questions have an answer that everyone can agree on.

    And this question comes from someone with an apostrophe in their name - surely a shameful practice that needs to be eradicated in the interest of making everyone's lives a little bit simpler. But don't tell De'Anthony Thomas I said that.

  • Larnu (11/4/2015)


    But you've corrected the question now. The question wasn't should you avoid "Create procedure [1Myproc]", it's "Create procedure 1Myproc". With the same respect i could therefore say that "sp_MyProc" is ok, as I've fixed the name and used "usp_MyProc".

    Create procedure [1Myproc]

    doesn't create a procedure called "[1MyProc]"

    it creates a procedure called "1MyProc"

  • If I want to be pedant, the right answer is "All of the above".

    Because of lacking of batch separator "GO".

    If you run the script no procedure is created.

  • I answered All of the Above because I understood it to be about practices, not syntax. I agree with others that bad syntax will be avoided because it won't work. However, while the other two answers are syntactically correct but both should be avoided according to https://www.mssqltips.com/sqlservertutorial/169/naming-conventions-for-sql-server-stored-procedures/

  • Carlo Romagnano (11/4/2015)


    If I want to be pedant, the right answer is "All of the above".

    Because of lacking of batch separator "GO".

    If you run the script no procedure is created.

    It's not meant to be run in its entirety as shown, they are alternatives.

    tom.w.brannon (11/4/2015)


    I answered All of the Above because I understood it to be about practices, not syntax. I agree with others that bad syntax will be avoided because it won't work. However, while the other two answers are syntactically correct but both should be avoided according to https://www.mssqltips.com/sqlservertutorial/169/naming-conventions-for-sql-server-stored-procedures/

    How can it be 'all of the above'? There's nothing wrong with option 4, particularly as the questioner says 'Note Myproc is a placeholder and could be any meaningful name'.

    Stewart "Arturius" Campbell (11/4/2015)


    sipas (11/4/2015)


    And this question comes from someone with an apostrophe in their name - surely a shameful practice that needs to be eradicated in the interest of making everyone's lives a little bit simpler. But don't tell De'Anthony Thomas I said that.

    Now that is just looking for trouble...

    Clearly you've never worked in Southern Ireland or France, where this is rather common...

    Having a middle name surrounded by double quotes is just looking for trouble...

  • I could argue a case for a couple of them, but I thought I knew what the author was getting at. The word "should" in the question also helped. The question may be a bit ambiguous, but the point of it is a good one.

  • sipas (11/4/2015)


    Carlo Romagnano (11/4/2015)


    If I want to be pedant, the right answer is "All of the above".

    Because of lacking of batch separator "GO".

    If you run the script no procedure is created.

    It's not meant to be run in its entirety as shown, they are alternatives.

    tom.w.brannon (11/4/2015)


    I answered All of the Above because I understood it to be about practices, not syntax. I agree with others that bad syntax will be avoided because it won't work. However, while the other two answers are syntactically correct but both should be avoided according to https://www.mssqltips.com/sqlservertutorial/169/naming-conventions-for-sql-server-stored-procedures/

    How can it be 'all of the above'? There's nothing wrong with option 4, particularly as the questioner says 'Note Myproc is a placeholder and could be any meaningful name'.

    Stewart "Arturius" Campbell (11/4/2015)


    sipas (11/4/2015)


    And this question comes from someone with an apostrophe in their name - surely a shameful practice that needs to be eradicated in the interest of making everyone's lives a little bit simpler. But don't tell De'Anthony Thomas I said that.

    Now that is just looking for trouble...

    Clearly you've never worked in Southern Ireland or France, where this is rather common...

    Having a middle name surrounded by double quotes is just looking for trouble...

    I was citing a source that recommended using a prefix on the stored procedures so the stored procedure should not just be an unqualified word/phrase. I found the wording of the question confusing, made my choice and got the result. The school solution and discussion contribute to my education.

  • I selected "all of the above", knowing I'd probably get it wrong. Because none of them are good practice. You should always check for existence of a procedure before creating it. If it's already there, all 4 of them will fail.

  • gvoshol 73146 (11/4/2015)


    I selected "all of the above", knowing I'd probably get it wrong. Because none of them are good practice. You should always check for existence of a procedure before creating it. If it's already there, all 4 of them will fail.

    nice one

  • paul 25096 (11/4/2015)


    I think the reason "Options 1, 2 and 3" has more votes than "Option 2" is because of course you should also avoid statements that cause a syntax error. The question could have been clearer!

    +1 If the question is "should you avoid", then "1, 2, and 3" is ALSO a correct answer. Perhaps the most complete of the possible selections. IMHO.

    Mike Hinds Lead Database Administrator1st Source BankMCP, MCTS

  • Well missed the true meaning of the question on that one.

  • Yeah, I think you generally "should" avoid writing code that is syntactically incorrect 🙂

  • I picked 1 & 3 option, because they were definitely going to throw an error. I wasn't aware of the "shouldn't use 'sp'" rule, which would make #1 doubly wrong. And I also wasn't thinking that anyone would be foolish enough to give their sproc the name of a system sproc. Which is bad on me, I normally try to think that everyone else is an utter moron 😛

  • Trick question. Don't like it.

    'Nuff said.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

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

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