日期:2014-05-17 浏览次数:20632 次
create table a (x char(10),y int)
go
create trigger [dbo].[a_limit] on [dbo].[a]
for insert
as
if exists(select 1 from inserted where y>0)
raiserror('错误',16,1)
go
set xact_abort on
begin tran
insert into a values('001',1)
insert into a values('002',2)
commit tran
go
--------结果---------
x y
001 1
002 2
create table a (x char(10),y int)
go
create trigger [dbo].[a_limit] on [dbo].[a]
instead of insert
as
if exists(select 1 from inserted where y>1)
raiserror('错误',16,1)
go
set xact_abort on
insert into a values('001',1)
insert into a values('002',2)
go
--------结果---------
x y
create table a (x char(3),y int)
set xact_abort on
insert into a values('001',1)
insert into a values('0032',2)
insert into a values('003',3)
set xact_abort off
go
select * from a
/*
(1 行受影响)
消息 8152,级别 16,状态 14,第 11 行
将截断字符串或二进制数据。
(1 行受影响)
x y
001 1
*/
set xact_abort on
begin tran
insert into a values('001',1)
insert into a values('0032',2)
insert into a values('003',3)
commit
set xact_abort off
go
select * from a
(1 行受影响)
消息 8152,级别 16,状态 14,第 12 行
将截断字符串或二进制数据。
(0 行受影响)
x y
----------