From the course: MySQL Advanced Topics (2019)

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Creating an index

Creating an index

- [Man] The most common way to create an index is to include it in your table definition. Here, I've copied this block of SQL from the chapter 1 exercise file. You notice it starts with use scratch, so we're using the Scratch database. We'll drop this table if it exists, so that we can create it right here with this create table statement. The table is called test, it has three columns, ID, string, and string 2, and notice the ID column, this is our primary key, auto increment, it has a not null constraint so you cannot insert null values, and it's an unsigned int. Now, we also have these two string columns, which are varchar and a show index statement to show all the indexes from the table test. Now, when I go ahead and execute all of this, it creates the table and we get the result of the show index statement and that result shows us one index, its named primary, this non unique is set to zero, which means that it…

Contents