• Primary key and Unique index


    SQL> create table t1(id1 char(2),id2 char(2),id3 char(2));
    
    Table created.
    
    SQL> desc t1
     Name					   Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID1						    CHAR(2)
     ID2						    CHAR(2)
     ID3						    CHAR(2)
    
    SQL> insert into t1 values('a',null,'a');
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> select * from t1;
    
    ID ID ID
    -- -- --
    a     a
    
    
    SQL> alter table t1
      add constraint PK_EMP primary key (id1,id2,id3);  2  
      add constraint PK_EMP primary key (id1,id2,id3)
                                             *
    ERROR at line 2:
    ORA-01449: column contains NULL values; cannot alter to NOT NULL
    
    
    SQL> create unique index t1_idx1 on t1(id1,id2,id3); 
    
    Index created.
    
    SQL> insert into t1 values('a',null,'a');
    insert into t1 values('a',null,'a')
    *
    ERROR at line 1:
    ORA-00001: unique constraint (SYS.T1_IDX1) violated

  • 相关阅读:
    c# 框架学习(nop )总结-------删除功能
    c# 框架学习(nop )总结-------编辑功能
    约束
    索引
    受限操作的变通解决方案
    删除数据表
    修改已有数据表
    定义外键
    定义主键
    定义默认值
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13352411.html
Copyright © 2020-2023  润新知