MariaDB root@(none):dyw> show index from dcount\G 0 rows in set Time: 0.024s
MariaDB root@(none):dyw> select * from dcount; +--------+--------+ | author | dcount | +--------+--------+ | dywang | 4 | | jenny | <null> | | linda | 3 | | peter | 2 | | rita | 1 | | sara | <null> | +--------+--------+ 6 rows in set Time: 0.024s
MariaDB root@(none):dyw> insert into dcount(author,dcount) values('dywang',12);
Query OK, 1 row affected
Time: 0.009s
MariaDB root@(none):dyw> select * from dcount; +--------+--------+ | author | dcount | +--------+--------+ | dywang | 4 | | jenny | <null> | | linda | 3 | | peter | 2 | | rita | 1 | | sara | <null> | | dywang | 12 | +--------+--------+ 7 rows in set Time: 0.022s
MariaDB root@(none):dyw> alter table dcount add unique key(author); You're about to run a destructive command. Do you want to proceed? (y/n): y Your call! (1062, "Duplicate entry 'dywang' for key 'author'")
MariaDB root@(none):dyw> delete from dcount where dcount=12; You're about to run a destructive command. Do you want to proceed? (y/n): y Your call! Query OK, 1 row affected Time: 0.029s
MariaDB root@(none):dyw> select * from dcount; +--------+--------+ | author | dcount | +--------+--------+ | dywang | 4 | | jenny | <null> | | linda | 3 | | peter | 2 | | rita | 1 | | sara | <null> | +--------+--------+ 6 rows in set Time: 0.022s
MariaDB root@(none):dyw> alter table dcount add unique key(author); You're about to run a destructive command. Do you want to proceed? (y/n): y Your call! Query OK, 0 rows affected Time: 0.078s
Non_unique: 0 表示不重複。add unique (field) 與 add unique key (field) 結果一樣。
MariaDB root@(none):dyw> show index from dcount\G ***************************[ 1. row ]*************************** Table | dcount Non_unique | 0 Key_name | author Seq_in_index | 1 Column_name | author Collation | A Cardinality | 6 Sub_part | <null> Packed | <null> Null | Index_type | BTREE Comment | Index_comment | 1 row in set Time: 0.006s
MariaDB root@(none):dyw> insert into dcount(author,dcount) values('dywang',12);
(1062, "Duplicate entry 'dywang' for key 'author'")
drop index author。
MariaDB root@(none):dyw> alter table dcount drop index author; You're about to run a destructive command. Do you want to proceed? (y/n): y Your call! Query OK, 6 rows affected Time: 0.099s
MariaDB root@(none):dyw> show index from dcount\G 0 rows in set Time: 0.004s