触发器更新问题 请问: 现在有一单据,在前台输入单据,保存时在后台利用触发器更新了该单据字段,怎样将实时将触发器更新的内容发发应到该单据上? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 --触发器的操作1create table 化验室纱组(本厂编号 int,客户 int,色号 int,纱支 int)create table 化验室布组(本厂编号 int,客户 int,色号 int,布类 int)gocreate trigger my_trig on 化验室纱组 for insert ,update ,deleteasif not exists(select 1 from inserted) delete 化验室布组 from deleted t where 化验室布组.本厂编号 = t.本厂编号 else if not exists(select 1 from deleted) insert into 化验室布组(本厂编号 ,客户 ,色号) select 本厂编号 ,客户 ,色号 from insertedelse update 化验室布组 set 客户 = t.客户 , 色号 = t.色号 from inserted t where 化验室布组.本厂编号 = t.本厂编号go--1、insert 对化验室纱组插入数据,然后查看化验室布组表的数据insert into 化验室纱组 values(1 , 2 , 3 , 4)insert into 化验室纱组 values(5 , 6 , 7 , 8)goselect * from 化验室布组/*本厂编号 客户 色号 布类 ----------- ----------- ----------- ----------- 1 2 3 NULL5 6 7 NULL(所影响的行数为 2 行)*/--2、update , 更改化验室纱组表中本厂编号=1的色号=6update 化验室纱组 set 色号 = 6 where 本厂编号 = 1goselect * from 化验室布组/*本厂编号 客户 色号 布类 ----------- ----------- ----------- ----------- 1 2 6 NULL5 6 7 NULL(所影响的行数为 2 行)*/--3、delete 化验室纱组表中本厂编号=1的那条数据delete from 化验室纱组 where 本厂编号 = 1goselect * from 化验室布组/*本厂编号 客户 色号 布类 ----------- ----------- ----------- ----------- 5 6 7 NULL(所影响的行数为 1 行)*/drop table 化验室纱组 , 化验室布组 为什么是触发器?保存时直接update不就行了么,再说了,前台已经改成新的了,你还要如何改到它的单据上?单据不是已经是新的了么.如果你一定要改单据的显示的东西,可以在更新数据库后,再立即查询数据,将查询结果写到单据上就行了. 两个表 有一个同名字段,怎么列出a表中有,b表中没有的行? 有关触发器的问题 查询问题,列变行,急!!! 先谢了 现有一个存储过程用到了游标,使用like模糊查询,效率非常低,请问有没有什么优化技巧 帮看一下这样的sql语句怎样写 请教64位的Windows Server 2003和SQL2005(64位)不能使用OpenDataSource的问题! 请教convert(float,x)类型转换的问题 SQL Server 2005数据库建表问题[谢谢!] 散分呀,大散分,不够再给,对了就给分,急!在线等待... vfp表格处理问题 以下代码如何执行 新手求助SQL2K转2005
create table 化验室布组(本厂编号 int,客户 int,色号 int,布类 int)
go
create trigger my_trig on 化验室纱组 for insert ,update ,delete
as
if not exists(select 1 from inserted)
delete 化验室布组 from deleted t where 化验室布组.本厂编号 = t.本厂编号
else if not exists(select 1 from deleted)
insert into 化验室布组(本厂编号 ,客户 ,色号) select 本厂编号 ,客户 ,色号 from inserted
else
update 化验室布组 set 客户 = t.客户 , 色号 = t.色号 from inserted t where 化验室布组.本厂编号 = t.本厂编号
go--1、insert 对化验室纱组插入数据,然后查看化验室布组表的数据
insert into 化验室纱组 values(1 , 2 , 3 , 4)
insert into 化验室纱组 values(5 , 6 , 7 , 8)
go
select * from 化验室布组
/*
本厂编号 客户 色号 布类
----------- ----------- ----------- -----------
1 2 3 NULL
5 6 7 NULL(所影响的行数为 2 行)
*/--2、update , 更改化验室纱组表中本厂编号=1的色号=6
update 化验室纱组 set 色号 = 6 where 本厂编号 = 1
go
select * from 化验室布组
/*
本厂编号 客户 色号 布类
----------- ----------- ----------- -----------
1 2 6 NULL
5 6 7 NULL(所影响的行数为 2 行)
*/--3、delete 化验室纱组表中本厂编号=1的那条数据
delete from 化验室纱组 where 本厂编号 = 1
go
select * from 化验室布组
/*
本厂编号 客户 色号 布类
----------- ----------- ----------- -----------
5 6 7 NULL(所影响的行数为 1 行)
*/drop table 化验室纱组 , 化验室布组
保存时直接update不就行了么,再说了,前台已经改成新的了,你还要如何改到它的单据上?单据不是已经是新的了么.
如果你一定要改单据的显示的东西,可以在更新数据库后,再立即查询数据,将查询结果写到单据上就行了.