Emulating Constants in SQL Server

  • Is there a best practice for emulating constants within SQL Server like those used in programming languages? Is it a combination of Defaults and UDDT's or should I set up Defaults and query some system table by name to get their values?

    Thanks

  • Depends. One of the biggest things you should try to avoid is using tables simple because you don't want to add to drive access if possible. I would use declared variables and set them at runtime. However this can make changes to code a bit harder and if you are using variables that can change periodically I would then use a table instead that way it is defined for all code without need to hunt and fix. Also depending on what exactly what is going on with the values you want to use as constants you can use case statements in your code as well (this is similar VBs "Select Case" or C/Javas "Switch" statements in many aspects) but again this is hard coded but that is normally the case for constants anyway.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • I agree. I'd put about much thought into whether I'd treat something as a constant as I would in an app. Have to weigh the chances of it changing and the time it would take to change vs increased development time/complexity. Proc's are arguably easier to change than compiled apps.

    Andy

  • Thank you for your suggestions.

Viewing 4 posts - 1 through 3 (of 3 total)

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