--大致写法如下:
create trigger my_trig on tb_Order for insert
as
insert into tb_Order_Log (FBillNO, FName, FTime, FNote )
select FBillNO , 这个登录用户比较麻烦, getdate(),FNote from inserted
go
--最好表tb_Order加个登录用户字段,把登录用户写入tb_Order表。就可以这样:
create trigger my_trig on tb_Order for insert
as
insert into tb_Order_Log (FBillNO, FName, FTime, FNote )
select FBillNO , FName, getdate(),FNote from inserted
go
------解决方案--------------------
SQL code
使用触发器完成
create trigger t1
on dbo.tb_Order
for insert
as
begin
insert into tb_Order_Log(FBillNO, FName, FTime, FNote )
select FBillNO,user_name(),getdate(),FNote
from isnerted
end
------解决方案--------------------
详情请参考http://blog.csdn.net/js_szy/archive/2009/11/30/4908948.aspx
------解决方案-------------------- create proc ins_order_log @fbillno int --输入单据号 . . --各种输入参数 . . as begin tran declare @rerurn int insert into tb_order(fbillno,......) select @fbillno...... if @@error<>0 begin goto err set @return=1 end insert into tb_order_log(TBILLNO) select @TBILLMNO err: rollback tran
------解决方案--------------------
------解决方案--------------------
SQL code
--大致写法如下:
create trigger my_trig on tb_Order for insert
as
insert into tb_Order_Log (FBillNO, FName, FTime, FNote )
select FBillNO , 这个登录用户比较麻烦, getdate(),FNote from inserted
go
--最好表tb_Order加个登录用户字段,
--1
create trigger my_trig on tb_Order for insert
as
insert into tb_Order_Log (FBillNO, FName, FTime, FNote )
select FBillNO , user_name(), getdate(),FNote from inserted
go
--2
create trigger my_trig on tb_Order for insert
as
insert into tb_Order_Log (FBillNO, FName, FTime, FNote )
select FBillNO , SYSTEM_USER, getdate(),FNote from inserted
go