Reputation: 191
I am trying to create a SQL database with the following structure. Essentially, it's an app where users can enter different leagues to receive questions about different TV shows. I realized, however, in my first table (i.e. 'user') I have a list of foreign keys that represent the leagues they're in and I am not sure if this is proper to do or if a list of foreign keys is possible in SQL. On the front end, I want the user to see the leagues they're in after logging in.
I have two questions:
Upvotes: 0
Views: 663
Reputation: 11
List of foreign keys is not recommended in SQL databases.
Instead, you should create another table of user id column and league id column. This table will show all the leagues that user have, that design uses the power of SQL database. Make a foreign key respectively of your needs. look at this answer of too: How to add list of foreign keys inside one column sql server
Upvotes: 1
Reputation: 246298
No, that doesn't look right. There should not be a foreign key constraint between league
and user
( a name that you should avoid, since it is an SQL keyword). Rather, league_user
should have a foreign keys pointing to both user
and league
, and the combination of the two foreign key columns is its natural primary key.
Upvotes: 1