O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – Creating a script to add a check constraint

Now we want to define the script which allows us to add a check constraint to the Products table.

  1. Open the file 0001_create_Products_table.sql we created during the preceding exercises.
  2. At the very end of the file, add a statement to delete the check constraint to be defined, if it already exists. The code should look similar to the following code snippet:
    IF EXISTS (SELECT * FROM sys.check_constraints WHERE object_id = OBJECT_ID('CK_Products_ReorderLevel') AND parent_object_id = OBJECT_ID('Products'))
    ALTER TABLE Product DROP CONSTRAINT CK_Products_ReorderLevel
    GO
  3. Add code to add a check constraint to the column ReorderLevel of the Products table which ensures that no value less than zero ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required