解决方案 »

  1.   


    alter table 课程表 add constraint check1 check(先行课<=课程ID)
      

  2.   

    我当然知道是加约束,关键是我不知道约束条件该怎么写...新手就是怎么麻烦是课程ID存在才能插入先行课?
    比如说,课程ID取值:C801,C802,C803,C804,C804。那么先行课取值就必须在(C801,C802,C803,C804,C804)内
      

  3.   

    觸發器檢查試試看,check約束好像沒辦法依賴其他列
      

  4.   

    create table tb
    (id int not null,
    name varchar(10) not null,
    pid int null,
    constraint PK_tb primary key nonclustered (id)
    )
    go
    alter table tb
       add constraint FK_self foreign key (pid)
          references tb (id)
    go
    alter table tb
    add constraint CHK_tb CHECK(pid<>id)