Home > Database > Mysql Tutorial > body text

MySQL创建index示例

WBOY
Release: 2016-06-07 15:18:16
Original
1287 people have browsed it

环境:MySQL Sever 5.1 MySQL命令行工具 问题:创建索引 CREATE INDEX 语法: CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name [index_type] ON tbl_name (index_col_name,...) [index_type] index_col_name: col_name [(length)] [ASC| DESC] index_typ

环境:MySQL Sever 5.1 + MySQL命令行工具


问题:创建索引

 

CREATE INDEX 语法:

 

CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name

[index_type]

ON tbl_name (index_col_name,...)

[index_type]

 

index_col_name:

col_name [(length)] [ASC| DESC]

 

index_type:

USING {BTREE | HASH |RTREE}

 

示例:


-- 创建无索引的表
create table testIndex ( 
  id int not null primary key, 
  name varchar(10) 
 ); 
 
-- 创建普通索引 
 create index IDX_test_testIndex _Name on testIndex(name); 
Copy after login


 

说明:索引的命名最好采用此种方式:IDX_databaseName_tableName_columnName(IDX表示索引,databaseName表示数据库名,tableName表示表名,columnName表示字段名,如果Oracle下不存在数据库的概念,取而代之的是表空间,所以databaseName替换成用户名即可)。


参考资料:

 

MySQL里创建索引(Create Index)的方法和语法结构及例子





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!