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,
...

Without getting into suitability of this for a specific purpose, your supertype-subtype model is “reversed”.
So DDL looks something like
Now, in order to read from this structure, create a view first
Look what happens when I want to select data which I know is from feed A. Note that
FeedTypeis not specified in this query, only column name which belongs toFeed_A(and common column).Notice that execution plan shows only
FeedandFeed_Atables, query optimizer eliminated tables_Band_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.