ALTER TABLE discount_codes ADD CONSTRAINT valid_values CHECK ( value >= 0 and ( type != '%' or (type = '%' and value <= 100) ) );