Database Reference
In-Depth Information
Listing 15-26. Creating Multiple CHECK constraints on a table
create table dbo.Orders2014
(
OrderId int not null,
OrderDate datetime2(0) not null,
OrderNum varchar(32) not null,
OrderTotal money not null,
CustomerId int not null,
constraint CHK_Orders2014_01
check(OrderDate >= '2014-01-01' and OrderDate < '2014-02-01'),
constraint CHK_Orders2014_02
check(OrderDate >= '2014-01-01' and OrderDate < '2014-03-01'),
constraint CHK_Orders2014_03
check(OrderDate >= '2014-01-01' and OrderDate < '2014-04-01'),
constraint CHK_Orders2014_04
check(OrderDate >= '2014-01-01' and OrderDate < '2014-05-01'),
constraint CHK_Orders2014_05
check(OrderDate >= '2014-01-01' and OrderDate < '2014-06-01'),
constraint CHK_Orders2014_06
check(OrderDate >= '2014-01-01' and OrderDate < '2014-07-01'),
constraint CHK_Orders2014_07
check(OrderDate >= '2014-01-01' and OrderDate < '2014-08-01'),
constraint CHK_Orders2014_08
check(OrderDate >= '2014-01-01' and OrderDate < '2014-09-01'),
constraint CHK_Orders2014_09
check(OrderDate >= '2014-01-01' and OrderDate < '2014-10-01'),
constraint CHK_Orders2014_10
check(OrderDate >= '2014-01-01' and OrderDate < '2014-11-01'),
constraint CHK_Orders2014_11
check(OrderDate >= '2014-01-01' and OrderDate < '2014-12-01'),
constraint CHK_Orders2014
check(OrderDate >= '2014-01-01' and OrderDate < '2015-01-01')
)
on [FG2014]
SQL Server evaluates all constraints during optimization and picks the most restrictive one.
Search WWH ::




Custom Search