create trigger tri_name on table tb for insert as begin if @@rownumber>0 begin insert into ta select * from inserted end end
CREATE TRIGGER tgr_test ON tmp_A FOR INSERT AS BEGIN INSERT INTO tmp_B ([xxx]) SELECT [xxx] FROM INSERTED ENDGO
CREATE TABLE tb1 (id INT) CREATE TABLE tb2 (id INT) CREATE TRIGGER t1 ON tb1 FOR INSERT AS INSERT tb2 SELECT * FROM inserted GO INSERT tb1 SELECT 1 SELECT * FROM tb2 /* id ----------- 1 */
create trigger tri_name on table tb for insert as begin if @@rowcount>0 begin insert into ta select * from inserted end end
create trigger my_trig on tb1 for insert as begin insert into b2(编号) select 编号 from inserted --or insert into b2 select * from inserted end
CREATE TRIGGER triggerInsertClearAlarm ON dbo.T_Stations FOR INSERTAS INSERT INTO T_ClearAlarm (StID, Type) VALUES (select StID from inserted,0) 这样写有问题么?
CREATE TRIGGER triggerInsertClearAlarm ON dbo.T_Stations FOR INSERTAS INSERT INTO T_ClearAlarm (StID, Type) select StID, Type from insertedgo
@@rownumber 提示必须声明变量,怎么弄?
CREATE TRIGGER trigger1 ON dbo.T_Stations FOR INSERT AS begin if @@rownumber>0 begin insert into T_ClearAlarm(StID) select StID from inserted end end GO
没必要用@@rownumber直接这样即可.CREATE TRIGGER trigger1 ON dbo.T_Stations FOR INSERT AS begin insert into T_ClearAlarm(StID) select StID from inserted end GO
for insert
as
begin
if @@rownumber>0
begin
insert into ta
select * from inserted
end
end
CREATE TRIGGER tgr_test ON tmp_A
FOR INSERT
AS
BEGIN
INSERT INTO tmp_B ([xxx]) SELECT [xxx] FROM INSERTED
ENDGO
CREATE TABLE tb2 (id INT)
CREATE TRIGGER t1 ON tb1
FOR INSERT
AS
INSERT tb2 SELECT * FROM inserted
GO
INSERT tb1 SELECT 1
SELECT * FROM tb2
/*
id
-----------
1
*/
for insert
as
begin
if @@rowcount>0
begin
insert into ta
select * from inserted
end
end
as
begin
insert into b2(编号) select 编号 from inserted
--or
insert into b2 select * from inserted
end
ON dbo.T_Stations
FOR INSERTAS
INSERT INTO T_ClearAlarm
(StID, Type)
VALUES (select StID from inserted,0)
这样写有问题么?
ON dbo.T_Stations
FOR INSERTAS
INSERT INTO T_ClearAlarm
(StID, Type)
select StID, Type from insertedgo
提示必须声明变量,怎么弄?
ON dbo.T_Stations
FOR INSERT
AS
begin
if @@rownumber>0
begin
insert into T_ClearAlarm(StID) select StID from inserted
end
end
GO
ON dbo.T_Stations
FOR INSERT
AS
begin
insert into T_ClearAlarm(StID) select StID from inserted
end
GO