请教一个事物的问题
2个表分别是
t1 有字段 A B C
t2 有字段 D E F
A字段为自增字段
需要写一个存储过程,向t1中添加数据,同时向t2中也添加数据D的值为刚向t1中添加数据的值,这个如何用事物实现?
------解决方案--------------------这个用触发器完成.
------解决方案----------------------寫trigger
create trigger tr_t1_i on t1 for insert
as
insert t2
select * from inserted
------解决方案--------------------CREATE TRIGGER mytrigger ON t1 FOR INSERT
AS
insert into t2(d) select max(a) from t1
GO
------解决方案--------------------CREATE TRIGGER mytrigger ON t1 FOR INSERT
AS
insert into t2 select * from t1
GO
或
CREATE TRIGGER mytrigger ON t1 FOR INSERT
AS
insert into t2 select * from t1 where a in (select max(a) from t1)
GO