触发器问题,高手帮忙

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.
...全文
13 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2003-04-03 08:28
社区公告
暂无公告