Solved

Tables Relations, best approach

Posted on 2013-01-11
7
412 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:ScottPletcher
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL 2014 get SPIDs of users 6 27
Database connection opened on a machine 8 37
IN with @variable 5 20
Restrict result set 1 0
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now