Skip to content
Advertisement

Could a foreign key column has multivalue in one row from the same reference table?

I’m trying to create a database on MySQL Workbench. Is it legal if a foreign key column has a multivalue in one row? I want to do that because based on the event category the user would be allowed to see the event or not. Also, there could be multiple event categories for one event. I know that I can make a composite key to event table. But I’m wondering that can I have multivalue as a foreign key in one row?

Here is my Event table:

And I want to store multiple categories in one ro. I want to do that because based on those categories, some of the users wouldn’t be allowed to see the event in the application.

Here is my category table:

Advertisement

Answer

And I want to store multiple categories in one ro. I want to do that because based on those categories, some of the users wouldn’t be allowed to see the event in the application.

No. Don’t got that way. This would denormalize your schema and make simple things utterly complex later on.

You have a many-to-many relationship between event and categories. The proper way to represent that is to create a third table, where each event/category table is stored on a separate row.

Something like:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement