SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 DB Design Sales Table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MevaD
Starting Member

32 Posts

Posted - 01/07/2014 :  18:19:44  Show Profile  Reply with Quote
Hi,

I am writing an application that will track sales opportunities and resulting work. The work that results from sales is classified into 3 distinct types each with a different set of attributes to track thus 3 tables.

So, my question is: what is the best way to set up primary keys and foreign keys in sales opportunities for the resulting work that will be generated?

Do I need to have columns for each of the work type tables in the sales table? That would result in NULL values in 2 of the Work ID columns in the sales table for each sale.

Is there a better/cleaner way to set this up. I'm especially concerned about pulling the data back later for reporting in an efficient manner.

Table: Sales
Sale_ID
Work_1_ID <-- ??
Work_2_ID <-- ??
Work_3_ID <-- ??

(Common set of attributes for all work types)

Table: Work_1 (Type 1)
Work_1_ID
Sale_ID

Table: Work_2 (Type 2)
Work_2_ID
Sale_ID

Table: Work_3 (Type 3)
Work_3_ID
Sale_ID

Thanks.

tkizer
Almighty SQL Goddess

USA
36907 Posts

Posted - 01/07/2014 :  18:38:43  Show Profile  Visit tkizer's Homepage  Reply with Quote
You don't need the work id references in the Sales table. You would use an outer join to the 3 tables to get all of the data you need.

Table: Sales
Sale_ID

(Common set of attributes for all work types)

Table: Work_1 (Type 1)
Work_1_ID
Sale_ID

Table: Work_2 (Type 2)
Work_2_ID
Sale_ID

Table: Work_3 (Type 3)
Work_3_ID
Sale_ID

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

MevaD
Starting Member

32 Posts

Posted - 01/08/2014 :  10:32:32  Show Profile  Reply with Quote
OK, thanks. Makes sense.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000