5
我想创建一个表,其中一列中的值不能大于下一列的值。例如,我正在创建下表。一列的值不能大于另一列
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);
而当前价格不能大于OriginalPrice。
所以我试图做是
CurrentPrice FLOAT CHECK (CurrentPrice <= OriginalPrice) NOT NULL,
但是这给了我以下错误:
Msg 8141, Level 16, State 0, Line 1
Column CHECK constraint for column 'CurrentPrice' references another column, table 'Price'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
不允许我在同一个表来引用列?