Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create index on create table

Can I create an index on a CREATE TABLE statement?
I.e. can I define indexes for a table when I create the table? I mean create the index on the create stamement sql command

like image 946
Jim Avatar asked Oct 16 '13 08:10

Jim


1 Answers

Yes, it can be defined in the CREATE TABLE, the convention is to put these definitions at the end of the list.

CREATE TABLE `example`
(
    `id` INTEGER  NOT NULL AUTO_INCREMENT,
    `index_col` VARCHAR(20),
    PRIMARY KEY (`id`),
    INDEX `index_name` (`index_col`)
)
like image 99
jpesout Avatar answered Oct 28 '22 09:10

jpesout