create clustered index index_name on student(name,code) 复合索引

解决方案 »

  1.   


    alter table student add constraint cons_01 unique (name,code) 
      

  2.   

    create table tb(id int,name varchar(50))alter table tb add constraint uniqueindex unique(id,name)insert into tb select 1,'a'insert into tb select 1,'a'
    --消息 2627,级别 14,状态 1,第 1 行
    --违反了 UNIQUE KEY 约束 'uniqueindex'。不能在对象 'dbo.tb' 中插入重复键。
    --语句已终止。
    select * from tb
      

  3.   

    增加一个 Check约束,表达式为Name<>Code
      

  4.   

    到底是(Name,Code)的组合唯一,还是Name<>Code...,今天头晕,看不懂 了,呵呵