插入后触发
Ttrigger after insert
我正在尝试编写将值 (+1) 输入到另一列的触发器。
如果我在 dbo 中添加新车。deelnemers/autonr 我的 dbo.auto's/risico 列应该添加值 +1
create trigger trRisicos
on deelnemers
after insert
as
begin
set nocount on;
declare u/autonr int
select u/autonr = inserted.autonr
from inserted
insert into autos
values (@autonr, 1)
end
这是我目前的代码。
dbo.deelnemers/autonr (PK, FK, INT, NOT NULL)
dbo.deelnemers/evenementnr (PK, FK, INT, NOT NULL)
dbo.autos/autonr (PK, INT, NOT NULL)
dbo.autos/typenaam (CHAR(50), NULL)
dbo.autos/bouwjaar (INT, NULL)
dbo.autos/waarde (INT, NULL)
dbo.autos/passagiers (INT, NULL)
dbo.autos/lidnr (FK, INT, NULL)
dbo.autos/Risico (SMALLINT, NULL)
试试这个:
create trigger trRisicos
on deelnemers
after insert
as
begin
set nocount on;
INSERT INTO autos (autonr, risico)
SELECT autonr, 1
FROM INSERTED;
end
我正在尝试编写将值 (+1) 输入到另一列的触发器。
如果我在 dbo 中添加新车。deelnemers/autonr 我的 dbo.auto's/risico 列应该添加值 +1
create trigger trRisicos
on deelnemers
after insert
as
begin
set nocount on;
declare u/autonr int
select u/autonr = inserted.autonr
from inserted
insert into autos
values (@autonr, 1)
end
这是我目前的代码。
dbo.deelnemers/autonr (PK, FK, INT, NOT NULL)
dbo.deelnemers/evenementnr (PK, FK, INT, NOT NULL)
dbo.autos/autonr (PK, INT, NOT NULL)
dbo.autos/typenaam (CHAR(50), NULL)
dbo.autos/bouwjaar (INT, NULL)
dbo.autos/waarde (INT, NULL)
dbo.autos/passagiers (INT, NULL)
dbo.autos/lidnr (FK, INT, NULL)
dbo.autos/Risico (SMALLINT, NULL)
试试这个:
create trigger trRisicos
on deelnemers
after insert
as
begin
set nocount on;
INSERT INTO autos (autonr, risico)
SELECT autonr, 1
FROM INSERTED;
end