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)
)

解决方案 »

  1.   


    alter table xsb add constraint zxf_constraint CHECK(zxf BETWEEN 0 AND 160) 
      

  2.   

    我可以在表里面直接
    zxf int default 0 check(zxf >=0 AND zxf<160),
    吗?
      

  3.   


    可以在表设计器中加上添加Check约束,并把 zxf BETWEEN 0 AND 160 添加到约束表达式中.
      

  4.   

    ---创建主键约束,唯一约束,检查约束
    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
      

  5.   

    举个简单例子create table t1
    (
    id int
    )
    alter table t1 add constraint id_check check(id between 0 and 160)
      

  6.   

    check约束
    alter table tablename constraint id_? check(id between 0 and 160)