使用CREATE INDEX创建索引
语法:
CREATE [UNIQUE] INDEX index_name ONtb_name (col_name [(length)] [ASC | DESC],...)
例:
#创建普通索引CREATE INDEX index_stu ON db_school.tb_student(studentNo);
#创建基于字段值前缀字符的索引CREATE INDEX index_course ON db_school.tb_course(courseName(3)DESC);
2.使用ALTER TABLE创建索引
语法:
ALTER TABLE tb_name ADD [UNIQUE | FULLTEXT][INDEX | KEY] [index_name] (col_name [(length)] [ASC | DESC],...)
例:
#使用ALTER TABLE创建普通索引
ALTER TABLE db_school.tb_student ADD INDEX idx_studentName(studentName);