I have a table with fields of PROSPECTS such as name, address, telephone etc...
One of the fields is the CURP and I want this column to contain unique data. The problem arises in that the records of prospects in this table are natural and legal persons, so not all of them have CURP, so the UNIQUE restriction does not work for me because although it accepts null values, it only accepts a null value in the entire column .
It occurs to me that I could define a condition with the CHECK constraint but I haven't found how to compare it with the other records in the table, only with the record that is entered.
Is it possible to generate this validation?
This is relatively easy to achieve using filtered indexes:
I get the impression that it can't. What yes, you can make a TRIGGER that validates the data, something like this: