The writers table structure :
Field name |
type of data |
Primary key |
Foreign key |
non empty |
only |
Self-increasing |
w_id |
SMALLINT(11) |
Yes |
no |
Yes |
Yes |
Yes |
w_name |
VARCHAR(255) |
no |
no |
Yes |
no |
no |
w_address |
VARCHAR(255) |
no |
no |
no |
no |
no |
w_age |
CHAR(2) |
no |
no |
Yes |
no |
no |
w_note |
VARCHAR(255) |
no |
no |
no |
no |
no |
1. Create a table writers in the database, the storage engine is MyISAM, and add a unique index named UniqIdx on the w_id field while creating the table
Step 1: Create a database
mysql> create database if not exists db2_idx character set utf8;
Query OK, 1 row affected (0.03 sec)
Step 2: Create tables and indexes
mysql> create table writers(
-> w_id SMALLINT(11) primary key unique auto_increment,
-> w_name VARCHAR(255) not null,
-> w_address VARCHAR(255),
-> w_age CHAR(2) not null,
-> w_note VARCHAR(255),
-> unique index index_id(w_id)
-> )engine=MyISAM;
Query OK, 0 rows affected, 1 warning (0.01 sec)
2. Use the alter table statement to create a common index of nameIdx on the w_name field
mysql> Alter table writers add index nameIdx (w_name);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
3. Use the CREATE INDEX statement to create a composite index named MultiIdx on the w_address and w_age fields
mysql> Create index MultiIdx on writers(w_address,w_age);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
4. Use the create index statement to create a full-text index named FTIdex on the w_note field
mysql> Create fulltext index FTIdex on writers(w_note);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
5. Delete the full-text index named FTIdex
mysql> Drop index FTIdex on writers;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0