create trigger tr_score_ins
on score
INSTEAD OF insert
as
if exists (select * from score a,inserted b where a.xh=b.xh and a.kmh=b.kmh)
begin
ROLLBACK TRANSACTION
end
on score
INSTEAD OF insert
as
if exists (select * from score a,inserted b where a.xh=b.xh and a.kmh=b.kmh)
begin
ROLLBACK TRANSACTION
end
解决方案 »
- 急!一条查询的sql语句
- 谁能写出这个check约束
- 两个表 有一个同名字段,怎么列出a表中有,b表中没有的行?
- 如何延长 Microsoft SQL Server 2008 试用期时间?
- 在作业中,如何删除指定时间之前的备份文件?
- 请教一个简单的SQL语句写法,谢谢~
- 不改变数据库SQL_Latin1_General_CP1_CI_AS排序规则,访问中文数据
- Sql server case...when ...then ...else 列转行 求优化!
- T-SQL 问题
- 请教关于服务器登录用户和数据库用户的区别和联系
- 關於 Character Set
- dw中的序号存入数据库,如何做?通过计算列产生序号存进去吗?
一个数据也插不进呀
create trigger tr_score_ins
on score
for insert
as
declare @xha char(20),@kcha char(20)
declare @cnt
select @xha=xh,@kcha=kch from inserted
select @cnt=count(*) from score where xh=@xha and kch=@kch
if @cnt>1
begin
ROLLBACK TRANSACTION
end
on score
for insert
as
if exists (select * from score a,inserted b where a.xh=b.xh and a.kmh=b.kmh)
begin
ROLLBACK TRANSACTION
end
inalover(奇遇)后面的写法再一次插入一行的情况下是对的。
create trigger tr_score_ins
on score
INSTEAD OF insert
as
if exists (select * from score a,inserted b where a.xh=b.xh and a.kmh=b.kmh)
begin
ROLLBACK TRANSACTION
end
INSERT score
SELECT * FROM INSERTED
GO
create trigger tr_score_ins
on score
for insert
as
if exists (select a.xh,a.kmh,COUNT(*) AS A from score a,inserted b where a.xh=b.xh and a.kmh=b.kmh GROUP BY a.xh,a.kmh HAVING COUNT(*)>1)
begin
ROLLBACK TRANSACTION
end
inalover(奇遇)后面的写法再一次插入一行的情况下是对的。
——————这个是不行的。这样可以插入同样的数据。