99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線(xiàn)電話(huà):13121318867

登錄
2022-04-06 閱讀量: 612
MySQL索引的操作

索引的操作

實(shí)際上索引也是一張表,創(chuàng)建索引時(shí),數(shù)據(jù)庫(kù)管理系統(tǒng)會(huì)在本地磁盤(pán)建立索引文件,里面保存了索引字段,并指向?qū)嶓w表的記錄。


創(chuàng)建索引

創(chuàng)建表的同時(shí)須指定索引名、表名和字段名。

create index  on ();


自動(dòng)創(chuàng)建索引

  • 在表中定義了主鍵約束時(shí),會(huì)自動(dòng)創(chuàng)建一個(gè)對(duì)應(yīng)的主鍵索引。

  • 在表中定義了外鍵約束時(shí),會(huì)自動(dòng)創(chuàng)建一個(gè)對(duì)應(yīng)的普通索引。

  • 在表中定義了唯一約束時(shí),會(huì)自動(dòng)創(chuàng)建一個(gè)對(duì)應(yīng)的唯一索引。

示例:emp表中的job添加普通索引

mysql> create index job_index on emp(job);


查看索引:

語(yǔ)法

show index from ;

示例:查看emp表中的索引

mysql> show index from emp;
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name  | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| emp   |          0 | PRIMARY   |            1 | empno       | A         |          14 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
| emp   |          0 | ename     |            1 | ename       | A         |          14 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
| emp   |          1 | deptno    |            1 | deptno      | A         |           3 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
| emp   |          1 | job_index |            1 | job         | A         |           5 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+


使用索引

在查詢(xún)語(yǔ)句中使用索引會(huì)大大提升數(shù)據(jù)的檢索速度。
示例

mysql> select ename,job,deptno from emp where job='salesman';
+--------+----------+--------+
| ename  | job      | deptno |
+--------+----------+--------+
| allen  | salesman |     30 |
| ward   | salesman |     30 |
| martin | salesman |     30 |
| turner | salesman |     30 |
+--------+----------+--------+


刪除索引

刪除索引只是刪除了表中的索引對(duì)象,表中的數(shù)據(jù)不會(huì)被刪除。
語(yǔ)法

drop index  on ;

示例

mysql> drop index job_index on emp;
mysql> select ename,job,deptno from emp where job='salesman';
+--------+----------+--------+
| ename  | job      | deptno |
+--------+----------+--------+
| allen  | salesman |     30 |
| ward   | salesman |     30 |
| martin | salesman |     30 |
| turner | salesman |     30 |
+--------+----------+--------+


加入CDA數(shù)據(jù)俱樂(lè)部,了解數(shù)據(jù)行業(yè)動(dòng)態(tài)和各行業(yè)數(shù)據(jù)信息 http://www.3lll3.cn/member.html?utm_source=weitao


0.0000 0 0 關(guān)注作者 收藏 編輯

評(píng)論(0)


字體

字號(hào)

代碼語(yǔ)言



發(fā)布評(píng)論


暫無(wú)數(shù)據(jù)

快速發(fā)帖 我要提問(wèn)


60.0074
0
關(guān)注作者
收藏
評(píng)論(0)

發(fā)表評(píng)論

暫無(wú)數(shù)據(jù)
推薦帖子