mysql索引查漏补缺
#创建一个普通索引
CREATE table test1(
id TINYINT UNSIGNED,
username VARCHAR(20),
index in_id(id),
key in_username(username))
#删除索引方法一
drop index in_id on test1;
#删除索引方法二
alter table test1 drop index in_username;
#修改索引方法一
CREATE index in_id on test1(id);
#修改索引方法二
alter table test1 add index in_username(username);
#创建一个唯一索引
CREATE table test2(
id TINYINT UNSIGNED AUTO_INCREMENT KEY,
uername VARCHAR(20) not NULL unique,
card char(16) not null,
UNIQUE key uni_card(card)
)
#创建全文索引
create table test3(
id TINYINT UNSIGNED AUTO_INCREMENT KEY,
username VARCHAR(20) not null UNIQUE,
userDesc VARCHAR(20) NOT NULL,
FULLTEXT full_userDesc(userDesc)
)
#创建单列索引
CREATE TABLE test4(
id TINYINT UNSIGNED AUTO_INCREMENT KEY,
test1 VARCHAR(20) NOT NULL,
test2 VARCHAR(20) NOT NULL,
test3 VARCHAR(20) NOT NULL,
test4 VARCHAR(20) NOT NULL,
INDEX in_test(test1)
)
#创建多列索引
CREATE TABLE test5(
id TINYINT UNSIGNED AUTO_INCREMENT KEY,
test1 VARCHAR(20) NOT NULL,
test2 VARCHAR(20) NOT NULL,
test3 VARCHAR(20) NOT NULL,
test4 VARCHAR(20) NOT NULL,
INDEX mul_t1_t2_t3(test1,test2,test3)
)
#创建唯一多列索引
CREATE TABLE test6(
id TINYINT UNSIGNED AUTO_INCREMENT KEY,
test1 VARCHAR(20) NOT NULL,
test2 VARCHAR(20) NOT NULL,
test3 VARCHAR(20) NOT NULL,
test4 VARCHAR(20) NOT NULL,
UNIQUE KEY mul_t1_t2_t3(test1,test2,test3)
)
#创建空间索引
CREATE TABLE test7(
id TINYINT UNSIGNED AUTO_INCREMENT KEY,
test GEOMETRY NOT NULL,
SPATIAL KEY spa_test(test)
) ENGINE MyISAM;
mysql与java日期函数