我写的触发器错在哪?

jjaacc 2002-12-25 11:12:45
create trigger t1
on authors
for insert
as
declare @name char(20)
select @name=i.au_lname from inserted i
print @name
if exists(select * from authors where au_lname=@name)
begin
raiserror('wrong',16,1) /*为什么老是执行这里?数据库里并没有我插入的数据*/
rollback transaction
end

插入:
insert into authors values('123-12-1232','csq','cc','234 233-2324','dsaf','ss','CA','23422',1)
...全文
27 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
j9988 2002-12-26
  • 打赏
  • 举报
回复
if exists(select 1 from authors where au_lname=@name group by au_lname having(count(*)>1))--如果有两条记录
j9988 2002-12-26
  • 打赏
  • 举报
回复
exists(select * from authors where au_lname=@name)
后触发器啊,它永远都存在.exists永远为真

34,594

社区成员

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

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