MySql使用create?index創(chuàng)建索引方式
MySql使用create index創(chuàng)建索引



1.創(chuàng)建普通索引
-- 列如:創(chuàng)建表book1給表中sno添加普通索引
-- 語法:create index 索引名 on 表名(字段名)
create table book1(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8)
)
create index index_book1 on book1(sno)2.創(chuàng)建唯一索引
-- 列如:給表book2中name添加唯一索引
-- 語法:create unique index 索引名 on 表名(字段名)
create table book2(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8)
)
create unique index index_book2 on book2(name)3.創(chuàng)建全文索引 fulltext
-- 列如:創(chuàng)建表book3給表中給sinfo添加全文索引
-- 語法:create fulltext index 索引名 on 表名(字段名)
create table book3(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200)
)
create fulltext index index_book3 on book3(sinfo)4.空間索引的創(chuàng)建 spatial
-- 列如:創(chuàng)建表book4給表中給sloc添加空間索引
-- 語法:create spatial index 索引名 on 表名(字段名)
create table book4(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
create spatial index index_book4 on book4(sloc)5.復(fù)合索引
-- 列如:創(chuàng)建表book5給表中給sno和name添加復(fù)合索引
-- 語法:create index 索引名 on 表名(字段名1,字段名2)
create table book5(
id int(8),
name varchar(20),
price float(3),
date varchar(20),
sno int(8),
sinfo varchar(200),
sloc point not null
)
create index index_book5 on book5(sno,name)
# 查看表中的索引
show index from book5總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
mysql unique key在查詢中的使用與相關(guān)問題
今天小編就為大家分享一篇關(guān)于mysql unique key在查詢中的使用與相關(guān)問題,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-04-04
解決mysql的賦權(quán)操作之GRANT ALL PRIVILEGES ON *.*
這篇文章主要介紹了解決mysql的賦權(quán)操作之GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ WITH GRANT OPTION問題,本文給大家分享兩種情況分析分享解決方案,感興趣的朋友一起看看吧2022-11-11
mysql執(zhí)行腳本導(dǎo)入表和數(shù)據(jù)后中文注釋亂碼的問題解決
本人在使用不同版本下進(jìn)行操作時(shí),就會(huì)出現(xiàn)中文亂碼的問題,,例如我本地安裝mysql8,服務(wù)器安裝的是mysql5,然后本地連接服務(wù)器的mysql后,執(zhí)行SQL腳本之后發(fā)現(xiàn)中文全部亂碼,所以本文介紹了mysql執(zhí)行腳本導(dǎo)入表和數(shù)據(jù)后中文注釋亂碼的問題解決,需要的朋友可以參考下2024-04-04
mysql行鎖(for update)解決高并發(fā)問題
這篇文章主要介紹了mysql行鎖(for update)解決高并發(fā)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-08-08

