Click here to Skip to main content
15,905,875 members
Home / Discussions / Database
   

Database

 
AnswerRe: How to select First Name? Pin
toxcct19-Jan-06 2:08
toxcct19-Jan-06 2:08 
GeneralRe: How to select First Name? Pin
Paul Conrad21-Jan-06 6:48
professionalPaul Conrad21-Jan-06 6:48 
QuestionMYSQL ERROR Pin
hbjs18-Jan-06 16:19
hbjs18-Jan-06 16:19 
AnswerRe: MYSQL ERROR Pin
hbjs18-Jan-06 16:46
hbjs18-Jan-06 16:46 
QuestionSQL 2005 - Auto connect to DB engines Pin
cmk18-Jan-06 14:46
cmk18-Jan-06 14:46 
AnswerRe: SQL 2005 - Auto connect to DB engines Pin
Dave Kreskowiak20-Jan-06 4:41
mveDave Kreskowiak20-Jan-06 4:41 
GeneralRe: SQL 2005 - Auto connect to DB engines Pin
cmk20-Jan-06 11:36
cmk20-Jan-06 11:36 
QuestionSQL Table Design Pin
Alexandru Serban18-Jan-06 10:39
professionalAlexandru Serban18-Jan-06 10:39 
Hi guys (and girls)

I have the folowing situation, a Person table, a Company table and a Contract table.
I can make contracts with both persons and companies alike so in the Contract table must be a referece to either a person or a company. In this case there are only two tables that need to link to the Contract table, but lets suppose there can be any number.
My initial approach is to create another table let's say Entity that has a column named EntityID that is the PK. In the Person table there is a PersonID column that is a PK for the Person table and a FK from the EntityID in the Entity table. The same applies to the Company table having a CompanyID column that is the PK for the Company table and a FK from the EntityID in the Entity table. The ID columns are GUIDs.
I use the EntityID as a FK in the Contract table to link either Person or Company to a contract in a SupplierID and a ClientID column.
While this design works, there is a small problem: acidentally deleting either a person or a company can leave an orphaned EntityID with no corespondece to the Person or Company table wich will leave the contract without one of its parts.

Is there other database design appropriate for this situation that overcomes this issue using referential integrity?


-- modified at 18:18 Wednesday 18th January, 2006

Just came up with another ideea, but it involves creating in the Entity table a new column for each referenced table (in this case Person and Company). In this case PersonID and CompanyID columns will be added to the Entity table and they will be FK from the Person and the Company table, for each Entity row only one of them having a value. After that, the row's EntityID will be used in the Contract table.
This works but new columns have to be created for each referenced table.

Is there any other solution?

AnswerRe: SQL Table Design Pin
Russell Nash19-Jan-06 1:54
Russell Nash19-Jan-06 1:54 
GeneralRe: SQL Table Design Pin
Alexandru Serban19-Jan-06 2:26
professionalAlexandru Serban19-Jan-06 2:26 
GeneralRe: SQL Table Design Pin
Russell Nash19-Jan-06 2:56
Russell Nash19-Jan-06 2:56 
QuestionGenerate Unique ID Pin
mcgann18-Jan-06 6:53
mcgann18-Jan-06 6:53 
AnswerRe: Generate Unique ID Pin
Farhan Noor Qureshi18-Jan-06 7:24
Farhan Noor Qureshi18-Jan-06 7:24 
QuestionER Diagrams Pin
kids1718-Jan-06 5:07
kids1718-Jan-06 5:07 
AnswerRe: ER Diagrams Pin
Colin Angus Mackay18-Jan-06 5:28
Colin Angus Mackay18-Jan-06 5:28 
QuestionMoving data between servers Pin
Russell Nash18-Jan-06 2:54
Russell Nash18-Jan-06 2:54 
GeneralRe: Moving data between servers Pin
PolarbearDK18-Jan-06 4:57
PolarbearDK18-Jan-06 4:57 
AnswerRe: Moving data between servers Pin
Farhan Noor Qureshi18-Jan-06 7:34
Farhan Noor Qureshi18-Jan-06 7:34 
Questionquery for unique customers Pin
imsathy18-Jan-06 2:22
imsathy18-Jan-06 2:22 
AnswerRe: query for unique customers Pin
Colin Angus Mackay18-Jan-06 2:50
Colin Angus Mackay18-Jan-06 2:50 
QuestionRe: query for unique customers Pin
imsathy18-Jan-06 3:17
imsathy18-Jan-06 3:17 
AnswerRe: query for unique customers Pin
Colin Angus Mackay18-Jan-06 4:00
Colin Angus Mackay18-Jan-06 4:00 
GeneralRe: query for unique customers Pin
imsathy18-Jan-06 18:32
imsathy18-Jan-06 18:32 
QuestionHow to assign dataset in Reporting Services 2005? Pin
Diego F.17-Jan-06 22:48
Diego F.17-Jan-06 22:48 
Questionmultiple update problem in datagrid Pin
sood_is_in17-Jan-06 21:24
sood_is_in17-Jan-06 21:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.