这是D7里的bug?插入带触发器的表出错!
本帖最后由 drsheldoncooper 于 2013-03-17 00:59:02 编辑 D7+MSSQL2000
有2张表ab,a里有触发器,当插入数据到a时,复制现在表a(不是inserted)的某个字段值到b
---------建表---------------
if exists(select * from sysobjects where name='a') drop table a
go
create table a
(
a_a char(10) primary key,
a_b int
)
go
if exists(select * from sysobjects where name='b') drop table b
go
create table b (b_a int)
go
-------------触发器--------------
create trigger a_insert on a
for insert
as
insert into b select a_b from a
go
------------用查询分析器进行插入----------------
begin tran
insert into a values('001',1)
insert into a values('002',2)
insert into a values('003',3)
commit tran
select * from a
select * from b
delete from a
delete from b
//adoquery1打开表a
adoquery1.AppendRecord(['001',1]);
adoquery1.AppendRecord(['002',2]);
adoquery1.AppendRecord(['003',3]);
adoconnection1.BeginTrans;
try
adoquery1.UpdateBatch;
adoconnection1.CommitTrans;
except
on e: exception do
begin
showmessage(e.Message);
adoconnection1.RollbackTrans;
end;
end;
delete from a
delete from b
//adoquery1打开表a
adoquery1.AppendRecord(['001',1]);
adoquery1.AppendRecord(['002',2]);
adoconnection1.BeginTrans;
try
adoquery1.UpdateBatch;
adoconnection1.CommitTrans;
except
on e: exception do
begin
showmessage(e.Message);
adoconnection1.RollbackTrans;
end;
end;
exec sp_executesql N'INSERT INTO "test".."a" ("a_a","a_b") VALUES (@P1,@P2); INSERT INTO "test".."a" ("a_a","a_b") VALUES (@P3,@P4); INSERT INTO "test".."a" ("a_a","a_b") VALUES (@P5,@P6); INSERT INTO
"test".."a" ("a_a","a_b") VALUES (@P7,@P8); INSERT INTO "test".."a" ("a_a","a_b") VALUES (@P9,@P10)',N'@P1 varchar(10),@P2 int,@P3 varchar(10),@P4 int,@P5 varchar(10),@P6 int,@P7 varchar(10),@P8 int,@P9
varchar(10),@P10 int','003 ',3,'002 ',2,'001 ',1,'002 ',2,'003 ',3
exec sp_executesql N'INSERT INTO "test".."a" ("a_a","a_b") VALUES (@P1,@P2); INSERT INTO "test".."a" ("a_a","a_b") VALUES (@P3,@P4)',N'@P1 varchar(10),@P2 int,@P3 varchar(10),@P4 int','001
',1,'002 ',2