DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to setup a restaurant inventory check constraint?

The following Microsoft SQL Server T-SQL code sample illustrates how to setup a table level constraint for a restaurant database:

-- Create constraint

ALTER TABLE dbo.RestaurantInventory

WITH NOCHECK ADD CONSTRAINT CK_RestaurantInventory_Type_Cost

CHECK ( (TYPE = 'Food'

 AND COST < (100)

  OR TYPE = 'Furniture'

     AND COST > (10)

     AND COST < (1000)) )

GO

 

-- Enable constraint

ALTER TABLE dbo.RestaurantInventory

 CHECK CONSTRAINT CK_RestaurantInventory_Type_Cost

GO

This constraint checks the range of cost for food items and restaurant furniture.

Related article:

Creating and Modifying CHECK Constraints

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE