I have a table with which I want to add a check constraint after it has already been created. I did some googling and found some answers, but they don’t appear to work. Here is what I have tried:
ALTER TABLE noise_table
ADD CONSTRAINT chk_level CHECK (noise_level >= 0 and noise_level <= 0.1);
However, after running this statement, I can still update and insert outside of the checked interval, so it doesn’t appear to be working at all. What am I missing here?
As documented under
ALTER TABLESyntax:You could instead define
BEFORE INSERTandBEFORE UPDATEtriggers that raise errors in the event that your criteria are not met: