在MySQL中创建三列的索引?
对于索引,可以使用KEY()
。让我们首先创建一个-
mysql> create table DemoTable1437 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentMarks int, -> StudentAge int -> , -> KEY(StudentId,StudentMarks,StudentAge) -> );
以下是查询以检查-的描述
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); mysql> insert into DemoTable1437 values(102,'David',89,22);
使用选择显示表中的所有记录-
mysql> select * from DemoTable1437;
这将产生以下输出-
+-----------+-------------+--------------+------------+ | StudentId | StudentName | StudentMarks | StudentAge | +-----------+-------------+--------------+------------+ | 101 | Chris | 78 | 21 | | 102 | David | 89 | 22 | +-----------+-------------+--------------+------------+ 2 rows in set (0.00 sec)