Solved

Table of Types Examples

Posted on 2014-03-18
2
261 Views
Last Modified: 2014-03-21
I've got dozens of "type" tables that are mostly identical and I would like to consolidate them all into a handful of tables. (i.e. a table of types)

For example, the tables Permit Type, Employee Type, Line Type, Vendor Type, etc.  all have the same basic columns:
X_Type_ID
X_Type_Name
Display_Color
Display_Order
Created_Date
Created_By
Last_Updated_Date
Last_Updated_By

There are a few that might have an additional attribute column, but for the most part they're just an ID and a Name.

Does anyone have a link to an example of creating a table of types, or just advice in general?
0
Comment
Question by:Torrwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 250 total points
ID: 39937447
Just because they're all structured similarly, doesn't mean you should consolidate them.  It also doesn't mean you shouldn't.  What matters is how you query them.

That said, you could create a new table, identical in structure to what you already have, but with a couple additional columns indicating what the record is a type of (and an index for the new, consolidated table), so something like...

ID
MetaType <- something indicating Permit, Employee, Line, Vendor, etc.
X_Type_ID
X_Type_Name
Display_Color
Display_Order
Created_Date
Created_By
Last_Updated_Date
Last_Updated_By

Bear in mind, this will necessitate rewriting ALL the queries that use these tables.
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 39938248
It's usually best to use a numeric code for the "metatype" / lookup_table_code for performance reasons.  Another table can contain the descriptive name of the underlying table.

For example, table "Permit Type" might be 1, "Employee Type" might be 2, etc..

Often a smallint allows enough values, you don't typically have to use a full int.

The combined table should be clustered on ( lookup_table_code, <lookup_value> [X_Type_Id] ).

That is, queries would still join to, say, table [Permit Type], but now it's a view, like this:
CREATE VIEW [Permit Type]
AS
SELECT
FROM dbo.lookup_table
WHERE
    lookup_table_code = 3 --<or> "= (SELECT lookup_table_code FROM lookup_table_directory WHERE name = 'Permit Type')"


>> Bear in mind, this will necessitate rewriting ALL the queries that use these tables. <<

Not necessarily.  You could instead create views with the same names as the existing tables.  Indeed, I'd strongly suggest using the combined lookup table that way anyway, rather than having each query specify the lookup table code.

Of course, once the view is created, it replaces the original table name completely, so the name then only points to the new table.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question