sql2000 判断表中字段数值是否改变,并把修改的数据记录到日志表里
时间:2011-12-01
来源:互联网
A表有 id、字段2、字段3、字段4、字段5...... (a表一共有61个字段包括id)
B表有 id ,字段名,旧数据,新数据,时间
B表是判断A表某些字段修改后的日志记录
前台修改程序用jsp,在jsp页面里有61个文本框,这61文本框就对应数据库A表的字段
假如A表字段8,字段20,字段26被改过
那么在B表里就有记录:
效果如下:
id 字段名 旧数据 新数据 时间
1 字段8 改前数据 改后数据 2011-12-01
2 字段20 改前数据 改后数据 2011-12-01
3 字段26 改前数据 改后数据 2011-12-01
我本来想用sql针对某个字段逐一判断,但由于字段比较多,不方便。不知有什么更好的方法。
作者: a2048 发布时间: 2011-12-01
作者: qianjin036a 发布时间: 2011-12-01
这个龙的走路方式很奇特.

作者: AcHerat 发布时间: 2011-12-01
在应用里可以将文本框做成对象数组,用循环的方法检查.
作者: qianjin036a 发布时间: 2011-12-01
引用 1 楼 qianjin036a 的回复:
这个龙的走路方式很奇特.
感觉当它两只右脚同时抬起来的时候,会向右侧摔下去.
作者: qianjin036a 发布时间: 2011-12-01
作者: ssp2009 发布时间: 2011-12-01
这个帮助巨龙吞噬魔怪的广告,这个龙的走路方式很奇特.
我怎么没看到龙
作者: pengxuan 发布时间: 2011-12-01
SQL code
--这里我只建了5个字段,楼主把剩下的55个字段补齐吧。累 :( if object_id('A','U') is not null drop table A go create table A ( id int, col1 varchar(10), col2 varchar(10), col3 varchar(10), col4 varchar(10), col5 varchar(10) ) go insert into A select 1,'col1','col2','col3','col4','col5' go if object_id('B','U') is not null drop table B go create table B ( id int identity(1,1), col varchar(10), 旧数据 varchar(10), 新数据 varchar(10), 时间 datetime ) go if object_id('tr_A','tr') is not null drop table tr_A go create trigger tr_A on A for update as if update(col1) insert into B(col,旧数据,新数据,时间) select 'col1',a.col1,b.col1,getdate() from deleted a inner join inserted b on a.id=b.id if update(col2) insert into B(col,旧数据,新数据,时间) select 'col2',a.col2,b.col2,getdate() from deleted a inner join inserted b on a.id=b.id if update(col3) insert into B(col,旧数据,新数据,时间) select 'col3',a.col3,b.col3,getdate() from deleted a inner join inserted b on a.id=b.id if update(col4) insert into B(col,旧数据,新数据,时间) select 'col4',a.col4,b.col4,getdate() from deleted a inner join inserted b on a.id=b.id if update(col5) insert into B(col,旧数据,新数据,时间) select 'col5',a.col5,b.col5,getdate() from deleted a inner join inserted b on a.id=b.id go update A set col1='col11',col2='col22',col3='col33',col4='col44',col5='col55' where id=1 go select * from b /* id col 旧数据 新数据 时间 ----------- ---------- ---------- ---------- ----------------------- 1 col1 col1 col11 2011-12-01 19:53:09.693 2 col2 col2 col22 2011-12-01 19:53:09.693 3 col3 col3 col33 2011-12-01 19:53:09.693 4 col4 col4 col44 2011-12-01 19:53:09.693 5 col5 col5 col55 2011-12-01 19:53:09.693 (5 行受影响) */
作者: pengxuan 发布时间: 2011-12-01
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28