
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Create index of three columns in MySQL?
For index, you can use KEY(). Let us first create a −
mysql> create table DemoTable1437 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentMarks int, -> StudentAge int -> , -> KEY(StudentId,StudentMarks,StudentAge) -> ); Query OK, 0 rows affected (0.97 sec)
Following is the query to check the description of −
mysql> desc DemoTable1437;
This will produce the following output −
+--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | StudentId | int(11) | YES | MUL | NULL | | | StudentName | varchar(20) | YES | | NULL | | | StudentMarks | int(11) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +--------------+-------------+------+-----+---------+-------+ 4 rows in set (0.01 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1437 values(101,'Chris',78,21); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable1437 values(102,'David',89,22); Query OK, 1 row affected (0.25 sec)
Display all records from the table using select −
mysql> select * from DemoTable1437;
This will produce the following output −
+-----------+-------------+--------------+------------+ | StudentId | StudentName | StudentMarks | StudentAge | +-----------+-------------+--------------+------------+ | 101 | Chris | 78 | 21 | | 102 | David | 89 | 22 | +-----------+-------------+--------------+------------+ 2 rows in set (0.00 sec)
- Related Articles
- Create index on create table in MySQL?
- Create Three Equal Columns with Bootstrap grid Layout
- Create three unequal Columns with Bootstrap grid layout
- Java program to create three vertical columns with equal number of buttons in GridLayout
- Create cross tabulation for three categorical columns in an R data frame.
- Finding index of rows and columns in SAP
- Add new MySQL table columns and create indexes?
- How can we create and use ENUM columns in MySQL?
- How to create conditions in a MySQL table with multiple columns?
- MySQL query to count where more than three columns values are true?
- Select distinct values from three columns and display in a single column with MySQL
- Python Pandas - Create a DataFrame with the levels of the MultiIndex as columns and substitute index level names
- Create Two Columns with Two Nested Columns in Bootstrap
- Exclude certain columns from SHOW COLUMNS in MySQL?
- Create index in a MongoDB collection?

Advertisements