USE Credit
go

SELECT count(*) FROM charge
go

SELECT MAX(charge_amt) FROM charge
go

set statistics io on
SELECT * FROM charge 
	WHERE charge_amt > 6000
go -- 0 ROWS... 9335 IOs (Table Scan)

ALTER TABLE charge
ADD CONSTRAINT ChargeChargeAmtCK
	CHECK (charge_amt < 5010)
go

SELECT OBJECTPROPERTY(object_id('ChargeChargeAmtCK'), 'CnstIsNotTrusted') -- should be 0 because the constraint is trusted...
go

SELECT * FROM charge 
	WHERE charge_amt > 6000
go -- 0 ROWS... 0 IOs 

ALTER TABLE charge
	DROP CONSTRAINT ChargeChargeAmtCK
go

ALTER TABLE charge
	WITH NOCHECK -- This is evil :)
ADD CONSTRAINT ChargeChargeAmtCK
	CHECK (charge_amt < 5010)
go
SELECT OBJECTPROPERTY(object_id('ChargeChargeAmtCK'), 'CnstIsNotTrusted') -- should be 1 because the constraint is not trusted...
go
DBCC CHECKCONSTRAINTS('charge')
go
SELECT OBJECTPROPERTY(object_id('ChargeChargeAmtCK'), 'CnstIsNotTrusted') -- should be 0 because the constraint is trusted...
go

SET STATISTICS IO ON
-- BACK TO A SCAN...don't use WITH NOCHECK!
SELECT * FROM charge 
	WHERE charge_amt > 6000
go -- 0 ROWS... 583 IOs (Table Scan)
