这个触发器如何编写?(50分)

  • 主题发起人 主题发起人 cansum
  • 开始时间 开始时间
C

cansum

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是两个表:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[adjust_price]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[adjust_price]
GO
CREATE TABLE [dbo].[adjust_price] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[upc] [int] NOT NULL ,
[date] [datetime] NOT NULL ,
[oriprice] [money] NOT NULL ,
[adprice] [money] NOT NULL
) ON [PRIMARY]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Item3]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Item3]
GO
CREATE TABLE [dbo].[Item3] (
[UPC] [int] IDENTITY (1, 1) NOT NULL ,
[Price] [money] NOT NULL
) ON [PRIMARY]
GO
希望在Item3表中的price表修改时,能够在adjust_price表中生成相应的记录:
upc 对应item3表中修改price的upc
[date] 为修改日期
oriprice 为修改前的price
adprice 为修改后的price
 
if updated(Price)
insert into adjust_price(upc, date, oriprice, adprice)
select i.upc, date(), d.price, i.price
from inserted i, deleted d
 
楼上的要改一下才能通过,不过还是很感谢!
if update(Price)
insert into adjust_price(upc, date, oriprice, adprice)
select i.upc, getdate(), d.price, i.price
from inserted i, deleted
 
呵呵,一时粗心.见谅见谅.
 
多人接受答案了。
 
后退
顶部