I have a table in which payments are stored, and you want to make sure that the payment method is a credit card, then the card type field should be IN ("Visa", "MasterCard", "Discover", "American Express"), however if the payment method is not a credit card, then the card type field must be NULL.
Will the check constraint allow me to use this operator:
(method = 'CC' AND cardType IN ('Visa', 'MasterCard', 'Discover', 'American Express'))
OR
(method != 'CC' AND cardType = NULL)
I could completely abandon this, since the restrictions should probably be used only for checking 1 field (not sure).
Also, if such approval is allowed, is there likely to be an adverse effect?
Edit: I plan, after all, to create a cardType field and have cardType in our payment table as a foreign key ... this is just what I am thinking of doing at the same time
source
share