2012年3月20日星期二

discrete domains in sql

I have a sql-table. The domain of one of my columns a fix number of string values (like "blue", "green" and "yellow"). However, there is a big likelyhood that the domain will be expanded by more string values in the future (however, none of the existing string values will ever be discluded from the domain). How would I go about enforcing that all strings added to my column in my table is within my domain?

Should I use a check constraint, or create a domain, or sholud a create another table with the domain values and use a foreign key? What would be best practise for my problem?

Any of the choices would work. The best choice will really depend on other things. Use the table or domain if that type of column could appear in other tables, otherwise use a Check constraint. The choice between the domain and the look-up table has more to do with the frequency of changes and who will be responsible. If changing the values is more of a business function, then the lookup table will be best.sql

没有评论:

发表评论