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.
不允許我在同一個表來引用列?