Getting rid of "Magic" numbers in SQL Server -


Once the application can specify a globally accessible static / enums / etc, once again through the application It can be used, it gives the ability to use meaningful names like 'Mazda' instead of numbers like '2'.

We want to do the same in our SQL server stored procedures, but it is not certain that the best method is

  Carm Manufacturer 350Z 1 Hilx 2 Yaras 2 Manufacturer Manufacturer 1 name Nissan 2 Toyota      

instead of typing

  select WHERE creator by car = 1 - Nissan  

We want to write something like from where the car maker selects = Nissan

Are have a restriction that we can not rely on the manufacturer. Life of the App We thought of having a "code" column that can never change and there are possibilities of joining:

  Select * Join Car C inner Manufacturer ON c.mainufacturerId = m.mainufacturerId WHERE M.Code = 'Nissan'  

I'm a bit hesitant because it uses an extra included and string comparison that is misspelled Might be possible.

What is the best way to accomplish this without declaring variables in every stored procedure?

We did this in two ways:

  • User defined The function that gives the name "magic number" by name
  • Instead of using an nchar (4) column instead of int column, and IA with a slightly less inscrutable code, then "NISN" will be in place of Nissan 1. A little good.

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -