我之前发布了一个类似的问题 - 但似乎无法得到足够长的回复!对不起,如果我不应该再次发布!
这是使用 SQL Server 2008。我有一个名为 invoice 的表;
create table INVOICE(
INVOICE_ID numeric(5) PRIMARY KEY IDENTITY,
INVOICE_STATUS varchar(25) not null,
TRADER_STATUS varchar (25))
我想在输入插入时创建触发器;并且 invoice_status = 'pending' - trader_status 更新(触发)为'open'。输入插入时;并且 invoice_status = 'overdue' - 将 trader_status 更新(触发)为 'blocked'。
我拥有的触发代码;
CREATE TRIGGER [dbo].[test] on [dbo].[invoice]
FOR INSERT, UPDATE
AS
BEGIN
SET NOCOUNT ON;
declare @invoice_status varchar(25)
select @invoice_status = (select invoice_status from inserted WHERE invoice_status = 'PENDING')
insert into invoice (trader_status) values ('OPEN')
select @invoice_status = (select invoice_status from inserted WHERE invoice_status = 'OVERDUE')
insert into invoice (trader_status) values ('BLOCKED')
END
GO
任何帮助是极大的赞赏!