createtableKeyDemo->(->idint,->primarykey(id)->);QueryOK,0rowsaffected(0.55sec) inserts two records."/> createtableKeyDemo->(->idint,->primarykey(id)->);QueryOK,0rowsaffected(0.55sec) inserts two records.">
Home >Database >Mysql Tutorial >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)
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)
Display all records.
mysql> select *from KeyDemo;
This is the output.
+----+ | id | +----+ | 1 | | 2 | +----+ 2 rows in set (0.00 sec)
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!