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

Database

 
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 
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 
Another is to take your second idea, and just roll it into the Contract table itself. That is, create an FK field for Person, and an FK field for Company, in the Contract table. Yes, this is poor normalization. However, you aren't gaining anything by splitting this out into an Entity table, and you're just increasing the complexity.

Well, it is not just the Contracts tabel involved, there are also invoices and all kinds of tabels that store documents and other data that can be applyed to either a persion or a company. And in this case there are only two root tabels but one can imagine a situation that has any number. Adding columns for every one in all the related tabels is not a viable option.
The Entity tabel offers a level of abstraction and restricts modifications to a single tabel.

Another is to create a pair of intermediary tables. Create a ContractPerson table, that handles contracts to people, and a ContractCompany table, that handles contracts to companies. You would need to add some logic, probably through triggers, to make sure that you don't have the same ContractID in both tables.

Again, creating intermediary tabels for every posible case is not a viable option.

But, probably your best bet is actually to drop back a step further. What exactly is the practical difference between Persons and Companies? You may want to significantly expand your Entity table to actually be the core of the system. It would include any information that is common to any customer, such as address. You would add a field that indicates if the Entity is a Person, Company, or whatever other categories you might have. You would then make child tables that handle data unique to the type of Entity.

Yes, this is the ideea. Entity is the core of the sistem. It links for example the Address table with the specific Person or Company, as a person or a Company can have multiple addresses.

So far the best solution is the one I came up the second time, addind a new column in the Entity table for each new table. And not only that, the EntityID equals the value of the column that has the value set(in this case PersonID or CompanyID). That is important because on the data layer I can create a Dataset that has a relation between let's say Person and Address.

One is to use triggers on the Person and Company tables to do brute force referential integrity on the EntityID table.

I want to restrict as much as possible the use of triggers to enforce referential integrity.
What I was wandering if is there a way to create what would logically be a column with multiple FK's that at any time it will corespond with only one PK in the reffered tabels. In this case EntityID would either link to PersonID or CompanyID so later adding other tabels considered as "entities" would be very easy.
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 
AnswerRe: multiple update problem in datagrid Pin
Alexandru Serban18-Jan-06 10:59
professionalAlexandru Serban18-Jan-06 10:59 
QuestionNeed Help With Creating an Easy Code. Pin
CoMMyz17-Jan-06 21:19
CoMMyz17-Jan-06 21:19 

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.