• Hugo Kornelis (5/2/2013)


    Good question, though I'm surprised that, apparently, people are doing this wrong. Since you'll be rewarded by an error message when you try, I don't understand how people could not do this correct - at least after being hit once.

    However, to do some nitpicking:

    1. If I were to try this code on my system, I would get five errors. All system table (*) names are completely lowercase, so everyone who has a server set up with a case sensitive collation will get error messages. (And I think every development server SHOULD be set up with case sensitive collation - developing there and deploying to a case insensitive server is okay, the other word around is a disaster)

    2. I don't see the advantage of using a system table (*) in this question. Why not add a CREATE TABLE to make a simple demo table and use that? Okay, it would have been a bit more code in the question, but it would save all the readers of having to look up if the various columns used in the question actaully exist in sysobjects.

    3. And if you must use a system table (*), at least avoid using the deprecated ones. You could have used sys.objects instead. Please don't encourage people to use compatibility views; they might just be gone in the next release!

    (*) Yeah, I know, I know. Not system tables, but system views. Or rather: compatibility view (for sysobjects) and object catalog view (for sys.objects)

    +1 🙂

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/