----------------------------------------------------------------
--                                                              
--  File:  Create_Check_Constraints_Growing.SQL                 
--          Microsoft TPC-E Benchmark Kit Ver. 1.14.0-1031      
--          Copyright Microsoft, 2008-2015                  
--                                                              
----------------------------------------------------------------
USE tpce
GO

-- *** HOLDING ***
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_H_PRICE' )
    ALTER TABLE HOLDING ADD CONSTRAINT CK_H_PRICE
	    CHECK (H_PRICE > 0)
GO

-- *** TRADE ***
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_T_IS_CASH' )
    ALTER TABLE TRADE ADD CONSTRAINT CK_T_IS_CASH
	    CHECK (T_IS_CASH in (0, 1))
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_T_LIFO' )
    ALTER TABLE TRADE ADD CONSTRAINT CK_T_LIFO
	    CHECK (T_LIFO in (0, 1))
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_T_BID_PRICE' )
    ALTER TABLE TRADE ADD CONSTRAINT CK_T_BID_PRICE
	    CHECK (T_BID_PRICE > 0)
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_T_TAX' )
    ALTER TABLE TRADE ADD CONSTRAINT CK_T_TAX
	    CHECK (T_TAX >= 0)
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_T_COMM' )
    ALTER TABLE TRADE ADD CONSTRAINT CK_T_COMM
	    CHECK (T_COMM >= 0)
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_T_CHRG' )
    ALTER TABLE TRADE ADD CONSTRAINT CK_T_CHRG
	    CHECK (T_CHRG >= 0)
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_T_QTY' )
    ALTER TABLE TRADE ADD CONSTRAINT CK_T_QTY
	    CHECK (T_QTY > 0)
GO

-- *** TRADE_REQUEST ***
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_TR_BID_PRICE' )
    ALTER TABLE TRADE_REQUEST ADD CONSTRAINT CK_TR_BID_PRICE
	    CHECK (TR_BID_PRICE > 0)
IF NOT EXISTS ( SELECT name FROM sys.check_constraints Where name = 'CK_TR_QTY' )
    ALTER TABLE TRADE_REQUEST ADD CONSTRAINT CK_TR_QTY
	    CHECK (TR_QTY > 0)
GO
