create table XSB
(
xh char(6) not null primary key,
xm char(8) not null ,
sex bit default 1,
csrq datetime,
zy char(12),
zxf int default 0,
bz varchar(500)
)
(
xh char(6) not null primary key,
xm char(8) not null ,
sex bit default 1,
csrq datetime,
zy char(12),
zxf int default 0,
bz varchar(500)
)
alter table xsb add constraint zxf_constraint CHECK(zxf BETWEEN 0 AND 160)
zxf int default 0 check(zxf >=0 AND zxf<160),
吗?
可以在表设计器中加上添加Check约束,并把 zxf BETWEEN 0 AND 160 添加到约束表达式中.
create table test
(
id int,
testname varchar(50),
sex bit,
class varchar(50),
score float default(0)
constraint pk_test primary key/*这里可以指定是创建聚集或非聚集索引clustered|nonclustered可选项*/(id)
constraint ix_test unique(testname)
constraint ck_test check/*这里可以使用 not for replication可选项,用于指定当从其他表中复制数据时,不检查约束条件*/(score>=0)
)
go
(
id int
)
alter table t1 add constraint id_check check(id between 0 and 160)
alter table tablename constraint id_? check(id between 0 and 160)