user194076 user194076 - 3 months ago 8
SQL Question

How to avoid one column table in database design

So, what would be the best approach to design relationship in a table when I have this setup:

Let's say I have tblFile that holds file path's to different files. and then I have bundles that can contain any amount of files.

So, my current structure is as follows:

enter image description here

How do I avoid creating tblBundle in this case (Because it doesn't need to contain any additonal information. But I still want it to be a key. And what would be a naming convention for "BundleId" column if I remove 2nd database)

Answer

If you do not need the one-column table, you do not have to create it. When the key is surrogate (i.e. have no meaning outside your data model) there is nothing wrong with having a non-primary key that does not reference other tables. You can index the column if you need faster access by BundleId.

There are advantages to having a table, though: you can make a foreign key with cascading delete, so deleting a row from the bundle table would automatically delete all its children rows.

Comments