In MySQL, use the PRIMARY KEY keyword to specify the primary key. The primary key is a field or field combination that uniquely identifies each row of records. It is unique (the primary key value is different for each row) and non-null (the primary key value is different). is NULL) property. Additionally, define the primary key using the following syntax: CREATE TABLE table_name ( column_name1 DATA_TYPE PRIMARY KEY, ... ).
Keywords for primary key in MySQL
In MySQL, the keyword used to specify the primary key isPRIMARY KEY.
Definition of primary key
The primary key is a field or combination of fields that uniquely identifies each row of records in a database table. It has the following properties:
Use the PRIMARY KEY keyword
To designate one or more fields as the primary key, use the PRIMARY KEY keyword when creating the table, as follows Display:
<code class="sql">CREATE TABLE table_name ( column_name1 DATA_TYPE PRIMARY KEY, column_name2 DATA_TYPE, ... );</code>
where:
table_name
is the name of the table. column_name1
is the name of the primary key field. DATA_TYPE
Specifies the data type of the field. Example
The following example creates a table named customers
where customer_id
is the primary key:
<code class="sql">CREATE TABLE customers ( customer_id INT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255) );</code>
In the above example, the customer_id
field is unique and non-null, which means that no two rows in the table have the same customer_id
value, and customer_id
The value is never NULL.
The above is the detailed content of What are the keywords of primary key in mysql. For more information, please follow other related articles on the PHP Chinese website!