如何在 MySQL 中创建三个列的索引?
对于索引,可以使用 KEY()。我们先创建一个 −
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)
以下是检查描述的查询 −
mysql> desc DemoTable1437;
这将产生以下输出 −
+--------------+-------------+------+-----+---------+-------+ | 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 在表格中插入一些记录 −
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)
使用 select 从表中显示所有记录 −
mysql> select * from DemoTable1437;
这将产生以下输出 −
+-----------+-------------+--------------+------------+ | StudentId | StudentName | StudentMarks | StudentAge | +-----------+-------------+--------------+------------+ | 101 | Chris | 78 | 21 | | 102 | David | 89 | 22 | +-----------+-------------+--------------+------------+ 2 rows in set (0.00 sec)
广告