Reputation: 6079
I have a customer file in MS ACCESS, it contains many tables.
Case:
In table(X) for Column(Y) there is validation rule of "=1 Or 2". I want to change it to "=1 OR 2 OR 3 OR 4" if Possible, Its an Byte column. Otherwsie i want to completly remove the validation rule for that column. I am using C# and i need a query to do so.......
Upvotes: 1
Views: 2409
Reputation: 97101
Access SQL can not be used to add, remove, or alter a Validation Rule. That can only be done through the DAO TableDef.
If you were using VBA in Access, you could do this to create your Validation Rule.
CurrentDb.TableDefs("X").Fields("Y").ValidationRule = "IN (1,2,3,4)"
I used IN (1,2,3,4)
instead of 1 OR 2 OR 3 OR 4
, but either should work.
Perhaps you can use Microsoft.Office.Interop.Access
to do the same from c#.
An alternative would be to create a check constraint with Access SQL. A check constraint is not the same as a Validation Rule, but could be used to accomplish the same goal.
ALTER TABLE X ADD CONSTRAINT one_to_four CHECK (Y IN (1,2,3,4));
You would still need to discard the existing Validation Rule. If that's not feasible, you could create a new table with the same structure as the old, add the check constraint, and finally load data from the old to the new table.
Upvotes: 2