amir amir
amir amir

Reputation: 3435

Two or more foreign key in the table

In MySQL I have these 3 tables :

CREATE TABLE IF NOT EXISTS Seasons
(
 season_id INT NOT NULL AUTO_INCREMENT,
 start_date DATE,
 end_date DATE,
 club_num INT,
 desc TEXT,
 PRIMARY KEY(season_id)
);

ALTER TABLE Seasons AUTO_INCREMENT=10000;



CREATE TABLE IF NOT EXISTS Clubs
(
 club_id INT NOT NULL AUTO_INCREMENT,
 club_name VARCHAR(70),
 PRIMARY KEY(club_id)
);

ALTER TABLE Clubs AUTO_INCREMENT=100000;


CREATE TABLE IF NOT EXISTS ClubsCloths
(
 season_id INT NOT NULL,
 club_id INT NOT NULL,
 first_shirt VARCHAR(50),
 second_shirt VARCHAR(50),
 PRIMARY KEY(season_id,club_id),
 FOREIGN KEY (season_id) REFERENCES Seasons(season_id),
 FOREIGN KEY (club_id) REFERENCES Clubs(club_id)
);

In the last one I have 2 foreign keys that reference to first and second table. Now I want to know is it wisely to have 2 foreign key in a one table ? thanks

Upvotes: 0

Views: 103

Answers (2)

Devart
Devart

Reputation: 122032

It is normal. The ClubsCloths table is used to support many-to-many relationship between Seasons and Clubs.

Upvotes: 1

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230531

It's perfectly normal to have several foreign keys to different tables (or the same table, doesn't matter).

Upvotes: 1

Related Questions