亚洲精品久久久久久第一页-人妻少妇精彩视品一区二区三区-91国产自拍免费视频-免费一级a在线播放视频正片-少妇天天日天天射天天爽-国产大屁股喷水视频在线观看-操美女骚穴抽插性爱视频-亚洲 欧美 中文字幕 丝袜-成人免费无码片在线观看

mysql上億數(shù)據(jù)秒級(jí)查詢 mysql查詢最后一條數(shù)據(jù)的id( 三 )


create table book (
bookid int not null,
bookname varchar(255) not null,
authors varchar(255) not null,
info varchar(255) null,
comment varchar(255) null,
publicyear year not null
);
創(chuàng)建好數(shù)據(jù)表book后,通過具體案例演示如何使用create index語句在已經(jīng)存在的數(shù)據(jù)表中創(chuàng)建索引,具體如下:
1) 創(chuàng)建普通索引
在book表中的bookid字段上建立一個(gè)名稱為index_id的普通索引,SQL語句如下:
create index index_id on book (bookid);
這樣,即可在book表中,為bookid字段建立一個(gè)名稱為index_id的普通索引 。
2) 創(chuàng)建唯一性索引
在book表中的bookid字段上建立一個(gè)名稱為uniqueidx的唯一性索引,SQL語句如下:
create unique index uniqueidx on book (bookid);
這樣,即可在book表中,為bookid字段建立一個(gè)名稱為uniqueidx的唯一性索引 。
3) 創(chuàng)建單列索引
在book表中的comment字段上建立一個(gè)名稱為singleidx的單列索引,SQL語句如下所示:
create index singleidx on book (comment);
這樣,即可在book表中,為comment字段建立一個(gè)名稱為singleidx的單列索引 。
4) 創(chuàng)建多列索引
在book表中的authors字段和info字段上建立一個(gè)名稱為mulitidx的多列索引,SQL語句如下所示:
create index mulitidx on book (authors(20), info(20));
這樣,即可在book表中,為authors和info字段建立一個(gè)名稱為mulitidx的多列索引 。
5) 創(chuàng)建全文索引
刪除表book,重新創(chuàng)建表book,在book表中的info字段上建立全文索引 。首先刪除book表 。SQL語句如下所示:
drop table book;
然后重新創(chuàng)建表book,SQL語句如下所示:
create table book (
bookid int not null,
bookname varchar(255) not null,
authors varchar(255) not null,
info varchar(255) null,
comment varchar(255) null,
publicyear year not null
)engine=MyISAM;
接下來使用create index 語句在book表的info字段上創(chuàng)建名稱為fulltextidx的全文索引,SQL語句如下所示:
create fulltext index fulltextidx on book (info);
這樣,即可在book表中,為info字段建立一個(gè)名稱為fulltextidx的全文索引 。
6) 創(chuàng)建空間索引
創(chuàng)建表t7,在表中的g字段上創(chuàng)建名稱為spatialidx的空間索引 。
首先創(chuàng)建數(shù)據(jù)表t7,SQL語句如下所示:
create table t7 (g geometry not null) engine=MyISAM;
使用create index 語句在t7表的g字段上,創(chuàng)建名稱為spatialidx的空間索引,SQL語句如下所示:
create spatial index spatialidx on t7 (g);
這樣,即可在t7表中,為g字段建立一個(gè)名稱為spatialidx的空間索引 。
修改表追加索引在一張已經(jīng)存在的數(shù)據(jù)庫表中創(chuàng)建索引,除了可以使用create index語句外,還可以使用alter table語句來完成 。其語法格式:
alter table 表名 add [unique|fulltext|spatial] index
索引名 (字段名 [(長度)] [asc|desc])
在上述語法格式中,unique、fulltext和spatial都是可選參數(shù),分別用于表示唯一性索引、全文索引和空間索引;add表示向表中添加字段 。
接下來,同樣以book表為例,對(duì)不同類型的索引進(jìn)行說明,為了使book表不包含任何索引,首先刪除book表,SQL語句如下:
drop table book;
然后重新建立book表,SQL語句如下:
create table book (
bookid int not null,
bookname varchar(255) not null,
authors varchar(255) not null,
info varchar(255) null,
comment varchar(255) null,
publicyear year not null
);
創(chuàng)建好數(shù)據(jù)表book后,就可以使用alter table語句在已存在的數(shù)據(jù)表中創(chuàng)建索引了,具體如下:
1) 創(chuàng)建普通索引
在表中的bookid字段上創(chuàng)建名稱為index_id的普通索引,SQL語句如下:


以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!

「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助: