Solved

Table of Types Examples

Posted on 2014-03-18
2
253 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
2 Comments
 
LVL 33

Assisted Solution

by:paulmacd
paulmacd 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:
ScottPletcher 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now