MySQL索引作业
表结构如下:
目录
writers表结构
字段名 数据类型 主键 外键 非空 唯一 自增
w_id SMALLINT(11) 是 否 是 是 是
w_name VARCHAR(255) 否 否 是 否 否
w_address VARCHAR(255) 否 否 否 否 否
w_age CHAR(2) 否 否 是 否 否
w_note VARCHAR(255) 否 否 否 否 否
(1)在数据库里创建表writers,存储引擎为MyISAM,创建表的同时在w_id字段上添加名称为UniqIdx的唯一索引
mysql> create table writers(
-> w_id smallint(11) not null primary key auto_increment,
-> w_name varchar(255) not null,
-> w_address varchar(255),w_age char(2) not null,
-> w_noto varchar(255),
-> unique index UniqIdx(w_id)
-> )ENGINE = MyISAM;
Query OK, 0 rows affected (0.00 sec)
(2)使用alter table语句在w_name字段上建立nameIdx的普通索引
mysql> alter table writers add index nameldx(w_name(255));
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
(3)使用CREATE INDEX 语句在w_address和w_age字段上面建立名称为MultiIdx的组合索引
mysql> create index Multildx on writers(w_address(255),w_age(2)); //创建多列索引
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
(4)使用create index语句在w_note字段上建立名称为FTIdex的全文索引
mysql> create fulltext index FTIdex on writers(w_noto);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
(5)删除名为FTIdx的全文索引
mysql> drop index FTIdex on writers;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0