Reputation: 1611
I have a table that holds all the attribute information for a series of codes. An attribute code is set up to hold only a certain data type. These include numeric, free text and dropdown values from a stored list.
I have created a table that holds all the attribute codes and their allowed values. I am trying to come up with a query that will validate each of the attributes on each of the codes based on the values in the validation table.
I'm trying to stay away from cursors as there is a large amount of codes that need to be checked and I know cursors do not perform very fast with a large number of rows.
You will notice from the LIST data types that they have a corresponding LIST_CODE and allowed LIST_VALUE.
Upvotes: 0
Views: 2187
Reputation: 725
While I'm reading your question again, you could do the following:
You simmply declare the columns in your data-Table as int, nvarchar(300) and float. A datatype is also a constraint and SQL-Server takes care that only values can be stored in a column that are allowed by the datatype.
You can do the same with your Attribute 0_OR_1. Just use the datatype bit in your data table. If you can't use bit for any reason and use tinyint you could add a CHECK CONSTRAINT to allow only the values 0 or 1:
ALTER TABLE DataTable
ADD CONSTRAINT CK_allow_only_0_or_1
CHECK ([0_OR_1_ATTR] = 0 OR [0_OR_1_ATTR] = 1);
Use a foreign key constraint for your dropdown You could create a ForeignKey-Constraint to store only allowed values for your dropdown
ALTER TABLE DataTable ADD CONSTRAINT FK_DropDownElements FOREIGN KEY (DROPDOWN_ATTR) REFERENCES ValidationTable (LIST_VALUE);
Upvotes: 1