sql 使用触发器如何update多条记录

来源:互联网 发布:远程网络教学系统类图 编辑:程序博客网 时间:2024/05/17 03:13
--begin 创建tb1表if (object_id('tb1', 'u') is not null)    drop table tb1gocreate table tb1(id int,name varchar(10),state int default(0)) declare @n int set @n=0while (@n<10)begininsert into tb1 (id,name)values(@n,'A'+cast( @n as varchar(5)))set @n+=1;endselect * into tb2 from tb1select * from tb1--end--begin 创建触发器if (object_id('DataSync', 'TR') is not null)    drop trigger DataSyncgocreate trigger DataSyncon tb1for updateas begin update tb2 set tb2.name=tb1.namefrom inserted as tb1 where tb2.id=tb1.id end --end--begin 测试update tb1set name='tb1_name'where id in (1,2,3,5,6,7)select * from tb1select * from tb2--end

参考:

SQL Update语句,更新表中的符合要求的多条记录,更新的值是从另一个表中调用的

url:http://bbs.csdn.net/topics/280054052

SQL Server 触发器

url: http://www.cnblogs.com/hoojo/archive/2011/07/20/2111316.html