Table with no relationships.

R

Robin Lawrie

Do all tables in a database need to be related to one or more tables?

For instance, is it bad database design to have a table with a customer id
but not create a relationship to another table?
 
D

Dirk Goldgar

Robin Lawrie said:
Do all tables in a database need to be related to one or more tables?

For instance, is it bad database design to have a table with a
customer id but not create a relationship to another table?

That depends on what you want to do with the database. If there's no
other table in the database that is logically related to the customer,
then you don't need a relationship to any other table. On the other
hand, if the reason you have no other related tables is that you've made
your Customer table with repeating fields like these ...

CustomerID
CustomerName
Contact1
Contact2
Contact3
Contact4
Purchase1
Purchase2
Purchase3
Purchase4
Purchase5
Purchase6
Purchase7
Purchase8
Purchase9
Purchase10
Purchase11
Purchase12
Purchase13
Purchase14
Purchase15

.... then you definitely have a faulty table design and *need* at least
two more, related tables -- one of CustomerContacts and one of
CustomerPurchases.
 
A

ad

Dirk Goldgar said:
That depends on what you want to do with the database. If there's no
other table in the database that is logically related to the customer,
then you don't need a relationship to any other table. On the other

Normally I don't specify relationships between tables. I only do links in
query design view, i.e. I only do that as needed on the go. Is this a bad
practice?

ad
 
V

Van T. Dinh

The main advantage of setting up relationships between
Tables is that you can enforce Referential Integrity as
well as the options "Cascade Update" and "Cascade Delete"
these will ensure that you don't have "orphaned" Chil
Records, i.e. the "Many" Records that are related to non-
existent "One" Records.

If you design your Forms / VBA code carefully to
avoid "orphaned" Records, the you shouldn't have any
problems.

HTH
Van T. Dinh
MVP (Access)
 
D

Dirk Goldgar

ad said:
Normally I don't specify relationships between tables. I only do
links in query design view, i.e. I only do that as needed on the go.
Is this a bad practice?

Maybe yes, maybe no. In this case, the *logical* relationships exist;
you just aren't enforcing them. Even if you open the Relationships
window and define a relationship between two tables, unless you check
the box to Enforce Referential Integrity, all you're doing is making a
pretty diagram that describes the logical relationships that you intend
should exist between the tables, and giving the Query Designer a clue
how to set up the join when both tables are added to a query's design
view. That's fine, so long as you realize that there is absolutely
nothing -- except your coding ingenuity and the good will of your
users -- to make sure that the logical relationship you have in mind
actually holds true in your data.

Once you put a check mark in that Enforce Referential Integrity box,
though, it's a different story. Now you've made it the responsibility
of the database engine to make sure that relationship always holds true.
From this moment on, it will simply refuse to store any data that would
contradict that relationship. It applies retroactively, too, in that
you won't even be able to create an enforced relationship is there is
already data in the table that would contradict it. This is a very
powerful tool for ensuring that the data stored in the database is
always valid according to the rules you have set up.

On the other hand, it can be cumbersome at times, for that very reason.
Mass updates and deletes have to be performed in the proper order. For
example, you can't delete all the records in a table and reload them
from some other source, if there is a child table that has an enforced
relationship to that table. Unless you want to delete all the child
records first, and restore them afterward, you have to drop the
relationship, do the delete and reload, and the recreate the
relationship. Thus, enforced relationships make you think carefully
about how to carry out operations of this sort -- but then, you *should*
think carefully about such things.

So ...

+ for a personal-use database where you have control over how data
is entered and can be sure that the logical relationship won't be
subverted by those pesky users, or

+ if the referential validity of the data is not very important, or

+ for special-use work tables on which you want to be able to
perform mass deletion and insertions without having to worry about
related records,

.... you don't need to create enforced relationships. But for any
serious application, where the validity of the data is important, or
when the database will be used by people other than yourself, then
defining relationships and enforcing referential integrity is absolutely
essential.
 
R

Robin Lawrie

Wow, thanks very much for this very detailed answer, it is very much
appreciated and clears up my question.

:)
 
J

John Vinson

Do all tables in a database need to be related to one or more tables?

No, not if there is no logical relationship.
For instance, is it bad database design to have a table with a customer id
but not create a relationship to another table?

Only if there is no information relating to customers in any of the
other tables.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
A

ad

Dirk Goldgar said:
Maybe yes, maybe no. In this case, the *logical* relationships exist;
you just aren't enforcing them. Even if you open the Relationships
window and define a relationship between two tables, unless you check
the box to Enforce Referential Integrity, all you're doing is making a
pretty diagram that describes the logical relationships that you intend
should exist between the tables, and giving the Query Designer a clue
how to set up the join when both tables are added to a query's design
view. That's fine, so long as you realize that there is absolutely
nothing -- except your coding ingenuity and the good will of your
users -- to make sure that the logical relationship you have in mind
actually holds true in your data.

Once you put a check mark in that Enforce Referential Integrity box,
though, it's a different story. Now you've made it the responsibility
of the database engine to make sure that relationship always holds true.
From this moment on, it will simply refuse to store any data that would
contradict that relationship. It applies retroactively, too, in that
you won't even be able to create an enforced relationship is there is
already data in the table that would contradict it. This is a very
powerful tool for ensuring that the data stored in the database is
always valid according to the rules you have set up.

On the other hand, it can be cumbersome at times, for that very reason.
Mass updates and deletes have to be performed in the proper order. For
example, you can't delete all the records in a table and reload them
from some other source, if there is a child table that has an enforced
relationship to that table. Unless you want to delete all the child
records first, and restore them afterward, you have to drop the
relationship, do the delete and reload, and the recreate the
relationship. Thus, enforced relationships make you think carefully
about how to carry out operations of this sort -- but then, you *should*
think carefully about such things.

So ...

+ for a personal-use database where you have control over how data
is entered and can be sure that the logical relationship won't be
subverted by those pesky users, or

+ if the referential validity of the data is not very important, or

+ for special-use work tables on which you want to be able to
perform mass deletion and insertions without having to worry about
related records,

... you don't need to create enforced relationships. But for any
serious application, where the validity of the data is important, or
when the database will be used by people other than yourself, then
defining relationships and enforcing referential integrity is absolutely
essential.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Very thorough explanation. I saved the post and will make sure details understood. Many thanks!!!

ad
 
A

ad

Thanks Van. The issue of deleting is something I didn't know before.
Interestingly, in one of my applications, I have a button for cleaning
empty and orphaned entries of various tables. Seems next time I'll have
a different approach.

By the way, I am a Mechanical Engineer, always learning programming by
using. I guess a lot of users are like me, who don't have proper training
in programming. They may be capable for some advanced tasks while may
not fully appreciate some of the basics at the same time. The good thing
is, with modern programs like MS Access, there are millions of ways to
achieve the same thing, some of them may be stupid but works:) Another
good thing is that there is always something new and exciting to learn,
like finding Easter eggs.

Thanks again.

ad
Sorry for the top posting. You did it first :)
 
Top