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