在SQL Server Management Studio中,我正在创建此表:
CREATE TABLE Purchase
(
PurchaseID INT NOT NULL
FOREIGN KEY REFERENCES Product(ProductID) PRIMARY KEY,
TotalQuantity INT NOT NULL,
Price AS (PurchaseID.PRICE),
TotalPrice AS (TotalQuantity*Price),
SalesAssistantID INT NOT NULL
FOREIGN KEY REFERENCES SalesAssistant(SalesAssistantID),
CashierID INT NOT NULL
FOREIGN KEY REFERENCES Cashier(CashierID)
)
以上代码仅代表我想要实现的目标(Price AS (PurchaseID.PRICE)
),只要指定Price
就应创建PurchaseID
,以便TotalCost
也可以自动运行,I无法解决这个问题。怎么做?
答案 0 :(得分:0)
PurchaseID int identity(1,1) Primary key
这使得purchaseID成为主键,(1,1)
表示它将从1开始并以1递增。