Solved

Tables Relations, best approach

Posted on 2013-01-11
7
416 Views
Last Modified: 2013-01-11
Hi, I have several doubts about this.

What I see before in relations is this:

Master -> student table
SchoolID
ClassID
StudentID
Name

Details -> movements
MovID
SchoolID
ClassID
StudentID
etc....

the other scenario is:


Master -> student table
ID Incremental
SchoolID
ClassID
StudentID
Name

Details -> movements
IDMaster ---the Master ID
etc. etc. ..

What is the best
0
Comment
Question by:Crashman
7 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 38767936
It's not clear to me what you're trying to design, but neither of those is properly designed.

For example, Student Name and ClassID should never be in the same table.
0
 
LVL 8

Author Comment

by:Crashman
ID: 38767956
ok,

Lets say,

-- Table Bill
Company
Date
DocNo
Client


--Table Bill details
Company -- foreign
DocNo -- foreign
ProductID
Quantity
Amount

in this, you have Two columns from Master.

-- Table Bill
ID --Incremental
Company
Date
DocNo
Client

--Table Bill details
IDRefParent --ID incremental from Parent
ProductID
Quantity
Amount

In this other I have only one column for reference...

is more clearly now?
0
 
LVL 8

Author Comment

by:Crashman
ID: 38768050
the scenario is more complicated, lets say we have a multiple foreign key in one table, and this table can not contains duplicates in this combinations of foreign keys and this table has a child table with only one field in common, how could you create relations between this two tablesExample
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 200 total points
ID: 38768075
For all many-to-many relationships, you have to create an "intersection" table.

You can use the two natural keys (better) or a single "dummy" generated id key (often poor for performance).

You would not use the full company name, of course, but instead a company code: that can be a code you make up or a legitimate standard id, such as a DUNS number.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 38768109
Taking your last example, you would want something more like this:

tblCompanies
-----------------------------------------
CompanyID (PK)
CompanyName

tblBills
-----------------------------------------
BillID (PK)
CompanyID (FK)
BillDate

tblBill Details
-----------------------------------------
BillDetailID (PK)
BillID (FK)
Product
Quantity
Amount
0
 
LVL 13

Accepted Solution

by:
LIONKING earned 300 total points
ID: 38768170
In order for you to create a one to many relation, your "one" table must be "uniquely identified" by your primary key.
The problem with the ID key is that it doesn't guarantee uniqueness of the other three fields, to do this, you would have to create a UNIQUE INDEX using these three columns.

If this uniqueness exists, you can perfectly create the one to many relation with those two tables. Because I assume your concern is that you will have the relation, but that doesn't mean that only unique values exist in table PARTIDAENC for a given key.
0
 
LVL 8

Author Comment

by:Crashman
ID: 38768421

tblCompanies
-----------------------------------------
CompanyID (PK)
CompanyName

tblBills
-----------------------------------------
BillID (PK) --this must be incremental, unless, tblBillDetails must have CompanyID ref.
                  --Multi companies
CompanyID (FK)
BillDate

tblBill Details
-----------------------------------------
BillDetailID (PK)
BillID (FK)
Product
Quantity
Amount
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

777 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