rhel4 mysql5.1 索引index_约束constraint创建_删除_查询

索引类型:

    普通索引,唯一索引,组合索引,主键索引(这些索引类型可能是并非并行关系),比如组合索引:可以是唯一索引或者普通索引等

    

 

普通索引:索引列可以有空值及重复值

唯一索引:索引列可以取空值,但险了空值列外,列值要唯一

主键索引:是唯一索引的特殊情况,一个表只能有一个主键索引,且索引列不能取空值

 

创建索引:

    分哪下几种方法,适应不同的情况,类似于oracle

    create index idx_1 on t1(username);

    alter table t1 add index idx_1 (username);

    alter table t1 add primary key(id);

 

mysql> alter table t1 add unique(username);#添加唯一索引
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

 

mysql> create unique index 1_idx on t1(username);#用create unique建立唯一索引
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>

请使用浏览器的分享功能分享到微信等