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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:01:09+00:00 2026-06-04T12:01:09+00:00

I just need some confirmation is database designed like this is fine or not.

  • 0

I just need some confirmation is database designed like this is fine or not. And if not am I doing something wrong here.
I have following tables:

TableA{TableAID,...}
TableB{TableBID,...}
TableC{TableCID,...}
etc.

And I have one table that I use like some kind of ‘news feed’. When I add something in any table A,B,C I also add row in this table.

Feed{FeedID, TypeID, ReferenceID,...}

FeedID is PK auto increment
TypeID is number that reference types table and based on this ID I know is row in this table from table A,B,C.
ReferenceId is ID of item in tables A,B,C.
A,B,C tables all have different fields.
Now when I want to get feed data I also need to grab some data from each of this table to use it in application. In my query to get this I use a lot SELECT CASE CLAUSE like:

I first join to all tables in query (A,B,C)

...
CASE Feed.TypeId              
               WHEN 1 THEN tableA.someData
                           WHEN 2 THEN tableB.someData
                           WHEN 3 THEN tableC.someData
          END AS Data,
...

enter image description here

  • 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-04T12:01:11+00:00Added an answer on June 4, 2026 at 12:01 pm

    Without getting into suitability of this for a specific purpose, your supertype-subtype model is “reversed”.

    enter image description here

    So DDL looks something like

    CREATE TABLE Feed ( 
          FeedID               integer  IDENTITY(1,1) not null
        , FeedType             char(1)  not null
      --  Common_Columns_Here
        , Common_Column        varchar(20)
    );
    ALTER TABLE Feed ADD CONSTRAINT pk_Feed PRIMARY KEY (FeedID) ;
    
    
    CREATE TABLE Feed_A ( 
          FeedID               integer  not null
      --  A_Specific_Columns_Here
        , A_Specific_Column    varchar(20)
    );
    ALTER TABLE Feed_A ADD
      CONSTRAINT  pk_Feed_A PRIMARY KEY (FeedID)
    , CONSTRAINT fk1_Feed_A FOREIGN KEY (FeedID) REFERENCES Feed(FeedID) ;
    
    
    CREATE TABLE Feed_B (
          FeedID               integer  not null
      --  B_Specific_Columns_Here
        , B_Specific_Column    varchar(20)
    );
    ALTER TABLE Feed_B ADD 
      CONSTRAINT  pk_Feed_B PRIMARY KEY (FeedID)
    , CONSTRAINT fk1_Feed_B FOREIGN KEY (FeedID) REFERENCES Feed(FeedID) ;
    
    
    CREATE TABLE Feed_C ( 
          FeedID               integer  not null
      --  C_Specific_Columns_Here
        , C_Specific_Column    varchar(20)
    );
    ALTER TABLE Feed_C ADD 
      CONSTRAINT  pk_Feed_C PRIMARY KEY (FeedID)
    , CONSTRAINT fk1_Feed_C FOREIGN KEY (FeedID) REFERENCES Feed(FeedID) ;
    

    Now, in order to read from this structure, create a view first

    create view vFeed as
    select
          f.FeedID
        , FeedType
        , Common_Column
        , A_Specific_Column
        , B_Specific_Column
        , C_Specific_Column
    from      Feed   as f
    left join Feed_A as a on (a.FeedID = f.FeedID and f.FeedType = 'A')
    left join Feed_B as b on (b.FeedID = f.FeedID and f.FeedType = 'B')
    left join Feed_C as c on (c.FeedID = f.FeedID and f.FeedType = 'C')
    ;
    

    Look what happens when I want to select data which I know is from feed A. Note that FeedType is not specified in this query, only column name which belongs to Feed_A (and common column).

    select
          FeedID
        , Common_Column
        , A_Specific_Column
    from vFeed;
    

    enter image description here

    Notice that execution plan shows only Feed and Feed_A tables, query optimizer eliminated tables _B and _C; no need to touch those two.

    In other words, you can ask for a specific feed data by simply using only specific columns in a query, and let the optimizer sort everything else out — no need for CASE ... WHEN .. acrobatics from your example.

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

Sidebar

Related Questions

I found this great code here the Demo . I just need some change.
Just need some help with this. I have written a WCF service which passes
I just need some advice on if this is wise. I'm loading my site
Im just starting with localization today and need some information. I have a project
Maybe I am just over thinking this and need to write some more prototype
Just need some quick guidance - I have a main frame, and I want
Just need some help to refine this query if possible. SELECT * FROM E_Associates
today i have direct a problem :P i just need some ideas... how do
this might be really simple, but just need some help in getting the syntax
Just need some help taking this hierarchical array... Array ( [root] => Array ([attr]

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.