Solved

Tables Relations, best approach

Posted on 2013-01-11
7
419 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
[X]
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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

740 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