• I do not like this kind of question at all. The QotD should be a learning opportunity, with clear questions and no tricks.

    There is nothing to be learned from this question. In a real situation, the error in the syntax would be obvious as soon as the code is executed, and it would be corrected before users get to add data.

    The lesson is:

    "GO" may be dangerous if no error checking is done!

    If that was the intended lesson, then the example is very badly chosen. Come on! How realistic is a script that adds a constraint and then immediately adds some data that obviously violates that constraint. I can only envisage that in a test database, where someone wants to test if constraints work as expected (not a bad idea, especially if NULL values are involved) - but in that case, checking the test output would immediately expose the problem and allow the developer to correct it. Which is the very purpose of running a test script.

    Another problem I have is that this kind of questions call for psychic powers on our part. Others have already commented that it might have been a honest mistake by the author, and we are suppose to answer based on a succesfull constraint creation (such errors and expectation have occured in the past).

    A problem not yet pointed out, but relevant in this and many other questions, is case sensitivity. Even if the missing parentheses are added, the constraint would still not be created in my test database, since I run a case sensitive collation (so "mytable" is not the same as "MyTable"). Other people will use different collations, and hence get a different result. How am I suppose to know what the author had in mind?

    This all being said, I'd still like to say "thank you" to bazzkar for contributing this question. Please take my reaction as it's intended, as constructive feedback. Don't let it discourage you from contributing more questions in the future, but do keep the feedback in mind to make your future questions better.


    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/