I have a following table, Client
.
create table Client (
ClientID int identity primary key,
TaxID varchar(12),
SSN varchar(12)
)
GO
Client can have either TaxID or SSN or both. But either one should exist.
Currently, I am enforcing the rule thru following trigger.
create trigger trgClient_UniqueTaxIDSSN
on Client
after Insert, Update
as
--; Check if either TaxID or SSN is not null.
But is there a way to declare a constraint to enforce the rule?
ALTER TABLE Client ADD CONSTRAINT ck_TaxIDorSSN CHECK
(TaxID is not null or SSN is not null)
You should be able to create a Check Constraint, on the Client table, to do this.
http://msdn.microsoft.com/en-us/library/ms188258.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With