January 2018
Intermediate to advanced
446 pages
12h 57m
English
You can add an index by executing the ALTER TABLE ADD INDEX command. For example, if you want to add an index on last_name, see the following code:
mysql> ALTER TABLE employees ADD INDEX (last_name);Query OK, 0 rows affected (1.28 sec)Records: 0 Duplicates: 0 Warnings: 0mysql> SHOW CREATE TABLE employees\G*************************** 1. row *************************** Table: employeesCreate Table: CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, `first_name` varchar(14) NOT NULL, `last_name` varchar(16) NOT NULL, `gender` enum('M','F') NOT NULL, `hire_date` date NOT NULL, PRIMARY KEY (`emp_no`), KEY `name` (`first_name`,`last_name`), KEY `last_name` (`last_name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ...Read now
Unlock full access