
SQL: Creating a Relational Table with Two Distinct Auto Increments
Problem:
You want to create a relational table with two auto-incremented columns, but you encounter an error.
Explanation:
Your attempt to establish a relational table with multiple auto-incremented columns is based on a misunderstanding of the concept of a primary key.
Key Concepts:
Mistake:
Resolution:
CREATE TABLE relational_table (
name_first CHAR(30),
name_last CHAR(30),
CONSTRAINT PK
PRIMARY KEY ( name_last, name_first )
)CREATE TABLE user_sport (
user_name CHAR(16) NOT NULL, -- FK
sport_code CHAR(4) NOT NULL, -- FK
start_date DATE NOT NULL,
CONSTRAINT PK
PRIMARY KEY ( user_name, sport_code )
)Benefits of Removal:
The above is the detailed content of How Can I Create a Relational Table with Two Separate Auto-Incrementing Columns?. For more information, please follow other related articles on the PHP Chinese website!