触发器,用于修改差异表上的多行,然后在SQL Server 2005中对其进行调用 [英] Trigger that modifies multiple rows on diffrent table then it was invoked on in SQL Server 2005
问题描述
我试图在被其他表更新触发的表上执行更新,并且收到错误消息:
行值已更新或删除
例如,我有此表:
table_1
===========
int id(primary_key,identity)
nchar(10)state_name
table_2
==========
整型数
在更新table_2之后,我想将 state_name列中的所有值都更改为 false
table_2
在更新
之后为
更新table_1 set state_name ='false'
当我尝试更新table_2时,收到错误消息。
有没有办法解决此限制?
创建表table_1(id int identity(1,1 )主键,state_name char(10))
创建表table_2(number int)
go
更新为更新table_1后在table_2上创建触发器tr设置state_name ='false'
go
插入table_1选择'true'
插入table_2选择1
go
更新table_2设置数量= 2
从表_1中选择*
从表_2中选择*
您使用哪个版本?在SQL 2K8和更高版本中效果很好。 SQL 2K5。再次检查您的代码。
I have tried to perform update on table which was trigger by update on other table and I got error message:
The row value(s) updated or deleted either do not make the row unique or they alter multiple rows.
For example I have this tables:
table_1
===========
int id (primary_key,identity)
nchar(10) state_name
table_2
===========
int number
And after updating table_2 I want to change all values in column 'state_name' to 'false'
create trigger tr on table_2
after update
as
update table_1 set state_name = 'false'
And when I try to update table_2 I receive error message. Is there a way to walk around this limitation?
create table table_1(id int identity(1,1) primary key, state_name char(10))
create table table_2 ( number int) go
create trigger tr on table_2 after update as update table_1 set state_name = 'false' go
insert table_1 select 'true' insert table_2 select 1
go
update table_2 set number = 2
select * from table_1
select * from table_2
Which version do you use? It worked out nicely in SQL 2K8 & SQL 2K5. Check your code again.
这篇关于触发器,用于修改差异表上的多行,然后在SQL Server 2005中对其进行调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!