我是这么写的
CREATE TRIGGER checkstudent ON aaa
FOR insert
AS
declare @id numeric
select @id=id from inserted
if exists (select * from aaa a join(select * from inserted) b on a.myid=b.myid where a.id<>@id)
begin
raiserror('此学号已存在',16,1)
delete from aaa where id=@id
-- rollback transaction
end
结果把重复的插入了
CREATE TRIGGER checkstudent ON aaa
FOR insert
AS
declare @id numeric
select @id=id from inserted
if exists (select * from aaa a join(select * from inserted) b on a.myid=b.myid where a.id<>@id)
begin
raiserror('此学号已存在',16,1)
delete from aaa where id=@id
-- rollback transaction
end
结果把重复的插入了
解决方案 »
- 感觉“数据库建模”一章内容挺抽象的,不容易理解,应该怎么学?
- 游标如何优化?
- 求一个字符串模式匹配的写法
- 如何增量生成当前修改(增加/删除)的字段的SQL语句
- 使用时raiserror遇到的特殊问题。
- 一个收缩数据库的问题,请各位帮忙解决!
- 求sql存储过程
- 现在数据库里一个 product 表,我想把 product 表里的东西 备份到bakproduct表里,怎么做?
- 跟一家20多个人的美容美体店做一个顾客管理程序,提供所有顾客的消费情况记录、指定顾客的消费记录查询和月收入统计等功能,开价多少?
- 如何向主键(标识自增1)的字段插入数据?
- 小弟初学写T_sql 函数,有好多的语法不会,请各位帮忙看看!,我很急!
- 请教:sql语句
FOR insert
AS
if exists (select id from aaa a
where id in (select id from inserted)
group by id having count(*)>1)
begin
raiserror('此id重复',16,1)
rollback transaction
end
FOR insert
AS
if exists (select id from aaa a
where id in (select id from inserted)
group by id having count(*)>1)
begin
raiserror('有id重复',16,1)
rollback transaction
end
instead of insert
as
insert 员工信息表(id,name)
select a.id,a.name
from inserted a left join 员工信息表 b on a.id=b.id
where b.id is nullif (select count(*) from inserted)>@@rowcount
RAISERROR('部分数据重复',1,16)