之間計算,我有兩個表PRODUCT
和INVOICE
:觸發SQL兩個表
Create table PRODUCT(){
PRODUCTID nvarchar(10), -- product id
PRICE float,
}
Create table INVOICE(){
PRODUCTID nvarchar(10),
QUANTUM int,
AMOUNT float,
}
現在我想創建Trigger
計算列AMOUNT
上INVOICE
,AMOUNT
= QUANTUM
* PRICE
感謝您的幫助!
create trigger trig_INVOICE
on INVOICE
after insert, update
as
begin
declare @price float
declare @ProductId nvarchar(10)
set @ProductID = (Select PRODUCTID from INVOICE)
set @price = (Select PRICE from PRODUCT where PRODUCT.PRODUCTID = @ProductId)
UPDATE INVOICE set AMOUNT = QUANTUM * @price
end
它不行-_-
這是什麼引擎? mySQL或SQL Server? – xQbert
到目前爲止,有什麼必須嘗試? –
爲什麼你需要一個列,創建一個視圖來獲得計算量值? – HaveNoDisplayName