O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Prefix index

For string columns, indexes that use only the leading part of column values, rather than the full column, can be created. You need to specify the length of the leading part:

## `last_name` varchar(16) NOT NULLmysql> ALTER TABLE employees ADD INDEX (last_name(10));Query OK, 0 rows affected (1.78 sec)Records: 0  Duplicates: 0  Warnings: 0

The maximum length of last_name is 16 characters, but the index is created only on the first 10 characters.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required