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.
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: SalesSale_IDWork_1_ID <-- ??Work_2_ID <-- ??Work_3_ID <-- ??(Common set of attributes for all work types)Table: Work_1 (Type 1)Work_1_IDSale_IDTable: Work_2 (Type 2)Work_2_IDSale_IDTable: Work_3 (Type 3)Work_3_IDSale_IDThanks. |
|
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: SalesSale_ID(Common set of attributes for all work types)Table: Work_1 (Type 1)Work_1_IDSale_IDTable: Work_2 (Type 2)Work_2_IDSale_IDTable: Work_3 (Type 3)Work_3_IDSale_IDTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
MevaD
Starting Member
32 Posts |
Posted - 2014-01-08 : 10:32:32
|
OK, thanks. Makes sense. |
|
|
|
|
|