表:RTVDetail
列:RTVNumber,SN,RTVStatus
表内容:
RTVNumber SN RTVStatus
WNRS06D005W 91U033602165 Q
WNRS06D006V 91U033602165 Q我要实现以下要求:
当更新RTVNumber为WNRS06D005W的时候把RTVStatus的值更新成T(Update RTVDetail Set RTVStatus='T' Where RTVNumber='WNRS06D005W')
同时把sn=91U033602165,RTVNumber=WNRS06D006V的这条记录中的RTVStatus也更新成T
结果是这样:
RTVNumber SN RTVStatus
WNRS06D005W 91U033602165 T
WNRS06D006V 91U033602165 T
这样的触发器怎么写?刚开始使用触发器,来帮帮我,解决立马给分
列:RTVNumber,SN,RTVStatus
表内容:
RTVNumber SN RTVStatus
WNRS06D005W 91U033602165 Q
WNRS06D006V 91U033602165 Q我要实现以下要求:
当更新RTVNumber为WNRS06D005W的时候把RTVStatus的值更新成T(Update RTVDetail Set RTVStatus='T' Where RTVNumber='WNRS06D005W')
同时把sn=91U033602165,RTVNumber=WNRS06D006V的这条记录中的RTVStatus也更新成T
结果是这样:
RTVNumber SN RTVStatus
WNRS06D005W 91U033602165 T
WNRS06D006V 91U033602165 T
这样的触发器怎么写?刚开始使用触发器,来帮帮我,解决立马给分
列:RTVNumber,SN,RTVStatus
表内容:
RTVNumber SN RTVStatus
WNRS06D005W 91U033602165 Q
WNRS06D006V 91U033602165 Q
我要实现以下要求:
当更新RTVNumber为WNRS06D005W的时候把RTVStatus的值更新成T(Update RTVDetail Set RTVStatus='T' Where RTVNumber='WNRS06D005W')
同时把sn=91U033602165,RTVNumber=WNRS06D006V的这条记录中的RTVStatus也更新成T
结果是这样:
RTVNumber SN RTVStatus
WNRS06D005W 91U033602165 T
WNRS06D006V 91U033602165 T
这样的触发器怎么写?刚开始使用触发器,来帮帮我,解决立马给分
补充:当我更新RTVNumber=WNRS06D005W 这条记录时把其它SN相等的RTVStatus都更新成T
insert into RTVDetail select 'WNRS06D005W','91U033602165','Q'
union all select 'WNRS06D006V','91U033602165','Q'
gocreate trigger cfq on RTVDetail
for update
asif @@rowcount=0 returnif update(RTVNumber)
begin
if exists(select 1 from inserted where RTVNumber='WNRS06D005W')
begin
Update a Set a.RTVStatus='T' from RTVDetail a,inserted b Where a.sn=b.sn and b.RTVNumber='WNRS06D005W'
end
end
goupdate RTVDetail set RTVNumber='WNRS06D005W'
goselect * from RTVDetaildrop trigger cfq
drop table RTVDetail
(
RTVNumber varchar(50),
SN varchar(50),
RTVStatus varchar(50)
)insert RTVDetail select 'WNRS06D005W','91U033602165','Q'
insert RTVDetail select 'WNRS06D006V','91U033602165','Q'
CREATE TRIGGER TEMP_SC on RTVDetail
AFTER update
as
update RTVDetail set RTVStatus='T' from RTVDetail R, inserted A where A.RTVNumber='WNRS06D005W' and R.SN=A.SN
for update
as
begin
if exists(select 1 from inserted a where a.RTVNumber='WNRS06D005W')
update RTVDetail Set RTVStatus='T' where RTVNumber='WNRS06D006V' and SN='91U033602165'
end
for update
as
begin
if exists(select 1 from inserted a where a.RTVNumber='WNRS06D005W')
update RTVDetail Set RTVStatus='T' where RTVNumber='WNRS06D006V' and SN='91U033602165'
end
create procedure test(@sn varchar(20))
as
Update RTVDetail Set RTVStatus='T' Where RTVNumber='WNRS06D005W'
Update RTVDetail Set RTVStatus='T' Where RTVNumber='WNRS06D006V'
Update RTVDetail Set RTVStatus='T' Where sn=@sn
goexec test '91U033602165'