Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6250671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:28:13+00:00 2026-05-24T13:28:13+00:00

I have a database design where i store image filenames in a table called

  • 0

I have a database design where i store image filenames in a table called resource_file.

CREATE TABLE `resource_file` (
  `resource_file_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `resource_id` int(11) NOT NULL,
  `filename` varchar(200) NOT NULL,
  `extension` varchar(5) NOT NULL DEFAULT '',
  `display_order` tinyint(4) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `canonical_name` varchar(200) NOT NULL,
  PRIMARY KEY (`resource_file_id`)
) ENGINE=InnoDB AUTO_INCREMENT=592 DEFAULT CHARSET=utf8;

These “files” are gathered under another table called resource (which is something like an album):

CREATE TABLE `resource` (
  `resource_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `description` text NOT NULL,
  PRIMARY KEY (`resource_id`)
) ENGINE=InnoDB AUTO_INCREMENT=285 DEFAULT CHARSET=utf8;

The logic behind this design comes handy if i want to assign a certain type of “resource” (album) to a certain type of “item” (product, user, project & etc) for example:

CREATE TABLE `resource_relation` (
  `resource_relation_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `module_code` varchar(32) NOT NULL DEFAULT '',
  `resource_id` int(11) NOT NULL,
  `data_id` int(11) NOT NULL,
  PRIMARY KEY (`resource_relation_id`)
) ENGINE=InnoDB AUTO_INCREMENT=328 DEFAULT CHARSET=utf8;

This table holds the relationship of a resource to a certain type of item like:

  • Product
  • User
  • Gallery
  • & etc.

I do exactly this by giving the “module_code” a value like, “product” or “user” and assigning the data_id to the corresponding unique_id, in this case, product_id or user_id.
So at the end of the day, if i want to query the resources assigned to a product with the id of 123 i query the resource_relation table: (very simplified pseudo query)

SELECT * FROM resource_relation WHERE data_id = 123 AND module_code = 'product'

And this gives me the resource’s for which i can find the corresponding images.

  • I find this approach very practical but i don’t know if it is a correct approach to this particular problem.
  • What is the name of this approach?
  • Is it a valid design?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:28:13+00:00Added an answer on May 24, 2026 at 1:28 pm

    To answer your second question first: the table resource_relation is an implementation of an Entity-attribute-value model.

    So the answer to the next question is, it depends. According to relational database theory it is bad design, because we cannot enforce a foreign key relationship between data_id and say product_id, user_id, etc. It also obfuscates the data model, and it can be harder to undertake impact analysis.

    On the other hand, lots of people find, as you do, that EAV is a practical solution to a particular problem, with one table instead of several. Although, if we’re talking practicality, EAV doesn’t scale well (at least in relational products, there are NoSQL products which do things differently).

    From which it follows, the answer to your first question, is it the correct approach?, is “Strictly, no”. But does it matter? Perhaps not.


    ” I can’t see a problem why this would “not” scale. Would you mind
    explaining it a little bit further? “

    There are two general problems with EAV.

    The first is that small result sets (say DATE_ID=USER_ID) and big result sets (say DATE_ID=PRODUCT_ID) use the same query, which can lead to sub-optimal execution plans.

    The second is that adding more attributes to the entity means the query needs to return more rows, whereas a relational solution would return the same number of rows, with more columns. This is the major scaling cost. It also means we end up writing horrible queries like this one.

    Now, in your specific case perhaps neither of these concerns are relevant. I’m just explaining the reasons why EAV can cause problems.

    “How would i be supposed to assign “resources” to for example, my
    product table, “the normal way”?”

    The more common approach is to have a different intersection table (AKA junction table) for each relationship e.g.USER_RESOURCES, PRODUCT_RESOURCES, etc. Each table would consist of a composite primary key, e.g. (USER_ID, RESOURCE_ID), and probably not much else.

    The other approach is to use a generic super-type table with specific sub-type tables. This is the implementation which Damir has modelled. The normal use caee for super-types is when we have a bunch of related entities which have some attributes, behaviours and usages in common plus seom distinct features of their own. For instance, PERSON and USER, CUSTOMER, SUPPLIER.

    Regarding your scenario I don’t think USER, PRODUCT and GALLERY fit this approach. Sure they are all consumers of RESOURCE, but that is pretty much all they have in common. So trying to map them to an ITEM super-type is a procrustean solution; gaining a generic ITEM_RESOURCE table is likely to be a small reward for the additiona hoops you’re going to have to jump through elsewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given the task to design a database to store a lot
I have a database design problem , where the database object's properties are not
For you database design/performance gurus out there. If you have a database that is
I have posted a question about multilanguage database design here, [] What are best
Does someone have any tips/advice on database design for a web application? The kind
What do I have to consider in database design for a new application which
I have to design a database to handle forms. Basically, a form needs to
Here's the situation. Due to the design of the database I have to work
I have database with many tables. In the first table, I have a field
I'm going to design a database for an image gallery in ASP.NET Web App

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.