请教:这句话该如何写?

jacky_hou 2004-02-18 12:52:51
有两个表
tabab1
f1(primary key) f2 f3
1 t1
2 t9
3 t8
...

table2
code content
t1 test1
t2 test2
t3 test3
t4 test4
t5 test5
t6 test6
t7 test7
t8 test8
t9 test9
...

现在想写一个触发器,使得当字段f2插入或更新的时候f3等于table2中content对应的值,
例如(插入的时候):
现在table1应该是这样的

tabab1
f1(primary key) f2 f3
1 t1
2 t9
3 t8
...
4 t3 test3
5 t7 test7
6 t8 test8
我的写法是这样的,但是不行,请各位指教?
create trigger test on table1
for insert,update
as
declare @f1
declare @f2
if update(f2)
select @f2=f2,@f1=f1 from inserted
update table1 set f3=(select top 1 B.content from inserted A,table2 B where A.@f2=B.code)
是不是没有这种写法(from inserted A)?

...全文
33 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复

34,576

社区成员

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

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