Home > Database > Mysql Tutorial > What does the KEY keyword in MySQL mean?

What does the KEY keyword in MySQL mean?

王林
Release: 2023-09-16 10:17:02
forward
1276 people have browsed it

What does the KEY keyword in MySQL mean?

Keys are synonymous with indexes. If you want to create an index on a column, use "Key".

As stated in the official documentation:

KEY is usually a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as KEY when given in the column definition. This is implemented for compatibility with other database systems.

This key can be used with the primary key:

Let us first create a table. Here is the query to set the primary key for the "id" column.

mysql> create table KeyDemo
    -> (
    -> id int,
    -> primary key(id)
    -> );
Query OK, 0 rows affected (0.55 sec)
Copy after login

Insert two records.

mysql> insert into KeyDemo values(1);
Query OK, 1 row affected (0.12 sec)

mysql> insert into KeyDemo values(2);
Query OK, 1 row affected (0.14 sec)
Copy after login

Display all records.

mysql> select *from KeyDemo;
Copy after login

This is the output.

+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of What does the KEY keyword in MySQL mean?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template