klintan
June 7th, 2005, 09:41 AM
I have a database design problem that I guess is very common, how to restrict code values in a database?
E.g. in a database you could have CustomerTypeCode, OrderTypeCode, ProductTypeCode, OrderLineCode, CustomerCategoryCode etc.
I can come up with at least three different designs that restricts these values in a database, but I would like to discuss pro's and con's of each of them, and maybe learn some other approaches as well.
Check constraints can be used
A code table per "type" can be used (e.g. CustomerTypes, OrderTypes)
A single table with all codes can be used, but in this case a CodeCategory is also needed to distinguish between different type of codes.
Currently, I use #2 if I have additional data associated to the "type" (for instance, I have a region table with region code, name, and some other data), and #3 for other codes.
Oh, and by the way I am using SQL Server and Access (both databases are supported by my applications).
E.g. in a database you could have CustomerTypeCode, OrderTypeCode, ProductTypeCode, OrderLineCode, CustomerCategoryCode etc.
I can come up with at least three different designs that restricts these values in a database, but I would like to discuss pro's and con's of each of them, and maybe learn some other approaches as well.
Check constraints can be used
A code table per "type" can be used (e.g. CustomerTypes, OrderTypes)
A single table with all codes can be used, but in this case a CodeCategory is also needed to distinguish between different type of codes.
Currently, I use #2 if I have additional data associated to the "type" (for instance, I have a region table with region code, name, and some other data), and #3 for other codes.
Oh, and by the way I am using SQL Server and Access (both databases are supported by my applications).