Create Procedure

  • Toreador (11/4/2015)


    Larnu (11/4/2015)


    Asking if you would avoid calling an sp 1MyProc, the simple answer is yes, because you can't do it.

    But you can do it - I gave you the syntax.

    Whether you would want to is another matter of course, and partly comes down to house rules (applying which my correct answer would be 'none of the above' as we call all stored procedures 'usp_xxx')

    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".

    If we follow this train of thought, and say that [1Myproc] is ok, is it really? The reason sp_MyProc is should be avoided is because it's bad practice, and could clash with an existing System sp. The reason you wouldn't use [1Myproc] is because starting object names with a numeric is bad practice, and so should still be avoided.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • 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.

  • This was removed by the editor as SPAM

  • 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 🙂

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

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