Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Database table structure

Posted on 2013-05-20
3
300 Views
Last Modified: 2013-05-20
One table "COMPANIES" needs to be linked to another table "CONTACTS".  Here is the twist: the contact for each company will change over time, but we need to keep the contacts.  My initial solution was to create a join table named something like "ACTIVE_CONTACT" that would hold pairs of the Company ID and the Contact ID, but i didn't know how to prevent a duplicate Company ID from being entered in the "ACTIVE_CONTACT" table. How would I do that?

Or, maybe using a join table is not the way to go?
0
Comment
Question by:rrhandle8
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39182896
A join table is the way to go. If you need to keep previous company contacts I would have a join table as you have described but rather than calling it active_contact just call it company_contacts and as well as the Company Id and Contact Id have another column called Active and make it a bit datatype which would be set for active contact records. You would make the Primary Key of this table a joint key of the Company Id and the Contact Id
Doing it this way means you would have a history of company contacts and the active contacts.

Alternatively if you felt that there was no need to keep a history of the contacts for each company in the company_contacts table you would just use Columns of Company ID and Contact ID and make them a company id the primary key for the join table to prevent duplicate contacts for a company. Obviously you will need logic in your stored procedures or business logic to delete a current active contact for a company when another is added.
0
 

Author Comment

by:rrhandle8
ID: 39182989
I've requested that this question be deleted for the following reason:

I decide to make the Company ID column unique.  
0
 

Author Closing Comment

by:rrhandle8
ID: 39182990
Jacko72,  I did not see your answer when I tried to delete the question.  I am awarding you now.  Thank you.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Pivot with row total 5 27
Compare a numeric value to a varchar w/o getting an error 4 20
RESTORE MASTER DATABASE -- NOW 2 20
Getting invalid Syntax SQL. 3 19
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

860 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