SQL: Creating a Relational Table with 2 Different Auto_increments
Understanding Auto_Increments and Relational Tables
In a true relational table, a column declared as a primary key is not automatically an auto-incremented ID.
Reasons for Avoiding Auto_Increments as Primary Key in Relational Tables:
Creating a Relational Table without Auto_Increments
Benefits of a Relational Table:
Example:
Consider the following relational table structure:
CREATE TABLE user ( user_name VARCHAR(30) NOT NULL, name_first VARCHAR(30) NOT NULL, name_last VARCHAR(30) NOT NULL, PRIMARY KEY (user_name, name_first, name_last) );
In this example, the primary key is composed of three columns, ensuring that each record represents a unique user. The absence of an auto-incremented ID column ensures that the table maintains row uniqueness without unnecessary overhead.
The above is the detailed content of Should I Use Auto-Increments as Primary Keys in Relational Database Tables?. For more information, please follow other related articles on the PHP Chinese website!