两个表的判断触发?

wfjyy 2008-12-10 03:59:33
两个表 table1 , table2, table3
table1

(no int
tt1 varchar
tt1_1 varchar
tt2 varchar
tt2_2 varchar

)
table2
(
tt varchar
)

table3
( no int
nrylb cahr(1) -- 1 代表tt 2 代表 tt2
)

当table1 update tt1_1 or tt2_2 时 与table2 tt比对 如果成功
把字符(1或2)插入到table3 nrylb
...全文
46 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wfjyy 2008-12-10
  • 打赏
  • 举报
回复
select 1 from table2

1 是什么意思?
-狙击手- 2008-12-10
  • 打赏
  • 举报
回复
create trigger trig_update
on table1
for update
as
begin
if update(tt1_1) or update(tt2_2) begin
insert into table3 select no,1 from inserted i where exists(select 1 from table2 where tt = i.tt1)
insert into table3 select no,2 from inserted i where exists(select 1 from table2 where tt = i.tt2)
end
end
go
-狙击手- 2008-12-10
  • 打赏
  • 举报
回复
两个表 table1 , table2, table3
table1 (no int tt1 varchar tt1_1 varchar tt2 varchar tt2_2 varchar )
table2 ( tt varchar )
table3 ( no int nrylb cahr(1) -- 1 代表tt 2 代表 tt2 )

当table1 update tt1_1 or tt2_2 时 与table2 tt比对 如果成功
把字符(1或2)插入到table3 nrylb

---

create trigger trig_update
on table1
for update
as
begin
if update(tt1_1) or update(tt2_2) begin
insert into table3 select no,1 from inserted i where exists(select 1 from table2 where tt = i.tt1
insert into table3 select no,2 from inserted i where exists(select 1 from table2 where tt = i.tt2
end
end
wfjyy 2008-12-10
  • 打赏
  • 举报
回复
table3有点错误,应该是

table3
( no int
nrylb cahr(1) -- 1 代表tt1 2 代表 tt2
)


[Quote=引用 1 楼 coolingpipe 的回复:]
与table2 tt比对 做何解?
[/Quote]

就是说 tt1_1 varchar 或者tt2_2 varchar 与 tt比对成功 才触发

关键是比对成功以后 我怎么去判断nrylb 是1 还是2
冷箫轻笛 2008-12-10
  • 打赏
  • 举报
回复
与table2 tt比对 做何解?

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧