Create index on create table in MySQL?

MySQLMySQLi Database

Let us first create a table and index −

mysql> create table DemoTable
   (
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   StudentFirstName varchar(20),
   StudentAge int,
   StudentCountryName varchar(100),
   INDEX first_Name_index(StudentFirstName)
   );
Query OK, 0 rows affected (1.01 sec)

Check the description of the table −

mysql> desc DemoTable;

This will produce the following output −

+--------------------+--------------+------+-----+---------+----------------+
| Field              | Type         | Null | Key | Default | Extra          |
+--------------------+--------------+------+-----+---------+----------------+
| StudentId          | int(11)      | NO   | PRI | NULL    | auto_increment |
| StudentFirstName   | varchar(20)  | YES  | MUL | NULL    |                |
| StudentAge         | int(11)      | YES  |     | NULL    |                |
| StudentCountryName | varchar(100) | YES  |     | NULL    |                |
+--------------------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
raja
Published on 03-May-2019 10:48:39
Advertisements