建立索引加快查詢速度:select * from t_user1 where username='測試'
1.建立表時建立索引
1)普通索引
CREATE TABLE t_user1(
id INT PRIMARY KEY AUTO_INCREMENT ,
username VARCHAR(20),
PASSWORD VARCHAR(20),
INDEX (username)
);
2)唯一索引,并為索引起别名
CREATE TABLE t_user2 (
id INT PRIMARY KEY AUTO_INCREMENT ,
username VARCHAR(20),
PASSWORD VARCHAR(20),
UNIQUE INDEX index_username ( username)
);
3)多列索引
CREATE TABLE t_user3 (
id INT PRIMARY KEY AUTO_INCREMENT ,
username VARCHAR(20),
PASSWORD VARCHAR(20),
INDEX index_username_password(username,PASSWORD)
);