首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

帮忙停这个sql语句为什么不能创建表

2014-01-03 
帮忙下这个sql语句为什么不能创建表create table test(id int not null primary key identity(1,1),xy int

帮忙下这个sql语句为什么不能创建表
create table test
(
id int not null primary key identity(1,1),
xy int  check( xy>[min] and xy<[max]),
[min] int default(0),
[max] int default(1000)
)
[解决办法]

引用:
这样是可以的,但是这样不是我的目的呀,我想让xy的取值介于min和max之间


这个得建立触发器:


create table test
(
id int not null primary key identity(1,1),
xy int ,
[min] int default(0),
[max] int default(1000)
)
go

create trigger dbo.trigger_test_insert
on test
for insert
as

if exists(select * from test where  not(xy>[min] and xy<[max]))
   rollback

go

--1.满足,不会报错
insert into test
select 10,1,11


--2.不满足条件,所以报错,插入不了
insert into test
select 10,1,10
/*
消息 3609,级别 16,状态 1,第 1 行
事务在触发器中结束。批处理已中止。
*/

热点排行