Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 DB Design Sales Table

Author  Topic 

MevaD
Starting Member

32 Posts

Posted - 2014-01-07 : 18:19:44
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

38200 Posts

Posted - 2014-01-07 : 18:38:43
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 - 2014-01-08 : 10:32:32
OK, thanks. Makes sense.
Go to Top of Page
   

- Advertisement -