Search code examples
sql-serverssms-2014

Avoid inserting a particular value into sql table


I am not sure, if this can be achieved in SQL.

INSERT INTO table_name (column1, column2, column3) 
VALUES (value1, value2, 999);

If the user tries to insert 999 in column3, convert it to null or avoid inserting it.

I am trying to find if I can find any solution from SQL Server side.


Solution

  • How about using a Check Constraint:

    ALTER TABLE table_name
    ADD CHECK (column3<>999);