触发器问题,高手帮忙

HawaiiLeo 2003-04-03 08:28:20
if exists(select name from sysobjects where name='AAA' and xtype='U')
drop table AAA
if exists(select name from sysobjects where name='BBB' and xtype='U')
drop table BBB

create table AAA(id int, num int, date datetime)
create table BBB(id int, num int, date datetime)

insert AAA values(1,2,'2001-1-5')
insert BBB values(1,2,'2001-1-5')
go

CREATE TRIGGER dbo.tr_AAA_u ON AAA
for update
as
update BBB
set BBB.num = AAA.num
where BBB.id = deleted.id

错误提示:
(1 row(s) affected)

(1 row(s) affected)

Server: Msg 107, Level 16, State 3, Procedure tr_AAA_u, Line 5
The column prefix 'AAA' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Procedure tr_AAA_u, Line 5
The column prefix 'deleted' does not match with a table name or alias name used in the query.
...全文
40 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
HawaiiLeo 2003-04-03
  • 打赏
  • 举报
回复
caiyunxia(monkey) 你写的运行成功,能解释一下为什么
update BBB
set BBB.num = AAA.num
where BBB.id = deleted.id

update BBB
set BBB.num = deleted.num
where BBB.id = deleted.id
为什么不对??
caiyunxia 2003-04-03
  • 打赏
  • 举报
回复

CREATE TRIGGER dbo.tr_AAA_u ON AAA
for update
as
update BBB
set num = AAA.num
FROM AAA,DELETED
where BBB.id = deleted.id AND AAA.ID=BBB.ID
HawaiiLeo 2003-04-03
  • 打赏
  • 举报
回复
zqllyh(学习Stupid As Pig中...) ,不好意思,你的答案也不对,错误提示:

Server: Msg 107, Level 16, State 2, Procedure tr_AAA_u, Line 5
The column prefix 'deleted' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Procedure tr_AAA_u, Line 5
The column prefix 'deleted' does not match with a table name or alias name used in the query.
zqllyh 2003-04-03
  • 打赏
  • 举报
回复
update BBB
set BBB.num = deleted.num
where BBB.id = deleted.id

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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