I want to create constraint orderDate must be smaller than deliveryDate? Help me.
Asked
Active
Viewed 117 times
0
-
1Have u tried anything???? First try by yourself and if u r not getting then ask the question.... – The Hungry Dictator Nov 11 '13 at 09:21
-
2`ALTER TABLE YourTable ADD CONSTRAINT CK_orderDate_Before_deliveryDate CHECK(orderDate < deliveryDate)` – Martin Smith Nov 11 '13 at 09:23
2 Answers
1
There are two ways to do it.
First While creating the table and after the creation:
While creating the table:
CREATE TABLE Price (
PriceID INT PRIMARY KEY IDENTITY (1,1),
OriginalPrice FLOAT NOT NULL,
CurrentPrice FLOAT NOT NULL,
Discount FLOAT,
ShippingCost FLOAT NOT NULL,
Tax FLOAT NOT NULL,
CHECK (CurrentPrice <= OriginalPrice));
After creation the table:
ALTER TABLE Price ADD CHECK (CurrentPrice <= OriginalPrice);
--or
ALTER TABLE Price ADD CONSTRAINT CK_Price_Current_vs_Original
CHECK (CurrentPrice <= OriginalPrice);
You can go for the date fields in the same sense. For more info please Read this.