Adding indexes when creating tables

You don’t have to wait until after creating a table to add indexes. In fact, doing so can be timeconsuming, as adding an index to a large table can take a very long time. Therefore, let’s look at a command that creates the table classics with indexes already in place.

Creating the table classics with indexes:
CREATE TABLE classics (
author VARCHAR(128),
title VARCHAR(128),
category VARCHAR(16),
year SMALLINT,
INDEX(author(20)),
INDEX(title(20)),
INDEX(category(4)),
INDEX(year)) ENGINE InnoDB;

Leave a Reply

Your email address will not be published. Required fields are marked *