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 8526359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:15:01+00:00 2026-06-11T08:15:01+00:00

Someone suggested to me to use a table as described here in a project,

  • 0

Someone suggested to me to use a table as described here in a project, and although I can’t say why, I don’t think it is a good idea.

MyTable (MyTableId PK, Type INT NOT NULL, MyForeignKey INT NOT NULL)

MyForeignKey can point to data in various tables depending on the value of Type. Of course, we cannot enforce FK integrity using such a model, but is this argument enough not to use it?

I’ll give you an example to where this could be used. Let’s say you have a Notes table in a system to save Notes about various objects; notes about Users, about Documents, etc. Normally, I would modelize this like this:

Notes (NoteId PK, Text VARCHAR(4000), UserId INT NULL, DocumentId INT NULL, …)

What my colleague proposes is to have such a table instead:

Notes (NoteId PK, Text VARCHAR(4000), ObjectType, ObjectId)

With the second implementation, ObjectType would tell us whether ObjectId is pointing to a row in the Users table or the Documents table. It has the advantage that the database structure and the code needs less modification if we want to add another type of objects.

What are the pros and cons of each solution?

Note: We will never have zillions of object types. It should remain below 10.

In fact our real life scenario is a bit more complex. It has to do with a permission system where Users may or may not have access to various types of objects (Documents, Notes, Events, etc.)

So for now in my database model, I have tables for these objects and additional tables to make relationship between them and users (UserDocuments, UserNotes, UserEvents, etc.) Permissions are set through Attributes in these link tables.

My colleague is proposing to have a single Permissions table instead like this

Permissions (PermissionId PK, UserId INT, ObjectType, ObjectId, … other permission fields…)

Is this a good idea?

Also, can we call this EAV or Open Schema? It is not exactly like what I have read on those topics.

  • 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-06-11T08:15:02+00:00Added an answer on June 11, 2026 at 8:15 am

    Well, in my honest opinion bot solutions are correct, but for different purposes. As you mentioned number of such types counts, and this is usually the only thing that drives the decision.

    I assume we are talking about OLTP system. So, if the number of types is relatively small, and you are sure it will not change (especially won’t grow up) you should choose the solution with separate columns for different types.

    If the number of types is big (in my opinion 10 is already a big number) you should choose the solution with type and key column.

    In general multicolumn variant is better, because you can use DBMS mechanisms to keep data integrity, wile when choosing type/key columns variant you have to develop those mechanisms on your own (i.e. triggers and procedures). Sometimes it is better to choose type/key column variant because the development and maintenance effort isn’t as big as structure change effort – if you don’t see any problems adding or removing FK columns to your tables during production use of your system you can still choose multicolumn variant (it is only a storage cost in that case).

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

Sidebar

Related Questions

Someone suggested moving a table full of settings, where each column is a setting
some one suggested me its a better idea to use float as a primary
I have a three tier set-up. Someone suggested I should get the ConnectionString from
Can someone suggest a fast 2 way encryption algorithm for long ints? My candidates
Can someone suggest me how to implement a pop-up window in Java Swing. I
Can someone suggest me a way to map a template classes with a set
Can someone suggest what I am doing wrong? Basically I have a List Items,
Can someone suggest how I can place a logo image on the top of
Can someone suggest me some JAVA string library for JAVA ME that includes basic
I am new to python programming..can someone suggest some way to do the following:

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.