Design with multiple tables suggestions

V

vm

Trying to figure the tables and relations for the following scenario:

Many users. Many machines with many accounts per machine.
Users have access to certain accounts on certain machines

I am just learning db and relations, but I was thinking of two tables.

One table with user info & what machine and account they have access to on
that particular machine.

A second table with the server name and accounts on it.

This is the first I have tried more than one table and joining. Any
suggestions? Is there a better way?

Thanks

vm
 
J

John Spencer

You have
Users
Accounts
Machines

You have many users who can use many accounts.
That implies the need for a UserAccounts table to record which users can use
which Accounts.

You have machines that can be used by many different accounts.
That implies that a MachineAccounts Table to record which accounts can be used
on which Machines.

You can then discover which users can use which machines by joining
UserAccounts to MachineAccounts.

In other words, I think you are going to need a minimum of 5 tables.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
K

Ken Sheridan

For someone as new to this sort of thing as you say you are you've done well
in terms of you analysis of the relationship types. You've not got the
relationships quite right though, and you are underestimating how many tables
are needed so I'll start from square one.

Firstly you should start with three tables which represent the three entity
types Servers, Accounts and Users, the first having one row per server, the
second one row per account and the third one row per user. These will
contain all the attributes of each entity type, ServerName, AccountName,
FirstName, Lastname etc. Also each will have a primary key column, which
I'll call S#, A# And U# for brevity, though something like UserID etc would
be better in reality.

What you need to do now is model the relationship types between these three
entities. Now it might be thought that the equivalent of your second table
on its own would do that, a table having columns S#, A# And U# as foreign
keys referencing the primary keys of the three 'referenced' tables. But lets
look at this with some data:

SAU
S# A# U#
1 1 2
1 2 1
2 3 1
2 4 1
2 4 2

Now this tells us all we need to know, that server 1 hold accounts 1 and 2,
server 2 holds accounts 3 and 4 and user 1 has access to accounts 2,3 and 4
and user 2 has access to accounts 1 and 4. So we don't need another table?
Wrong!

Lets assume that user 2 falls under a bus on his way to work one day, so his
employment is terminated with extreme prejudice. OK, we delete user 2 from
the users table and the first and last rows from the SAU table above. But
hold on, what's happened to account 1? We no longer know where it is. So we
have to decompose SAU into two tables:

SA
S# A#
1 1
1 2
2 3
2 4

AU
A# U#
1 2
2 1
3 1
4 1
4 2

If we now join these tables on A# the result is the original SAU, so the
decomposition has been 'non-loss', which is what it should be. We can now
delete the first and last rows from AU, but we still know that account 1 is
on server 1 from the first row in SA. We can now all have a morning away
from the office at user 1's wake, drinking lots of Guinness without having to
worry about where account1 is.

So, you were heading in the right direction! The only real mistake you made
as regards the relationship types was redundantly including the server in
your first table; and you didn't identify the need for the three main
referenced tables.

This process can in some circumstances be extended beyond this. In reality
it wouldn't apply in this scenario as it would mean having the same account
on more than one server, but if we unrealistically assume that to be the case
then joining the two tables could produce a result table which includes
spurious rows not present in the original SAU table. In that situation it
would be necessary to decompose it into three tables, adding a SU table to
the SA and AU tables. This would be normalization to Fifth Normal Form
(5NF), also known as Projection-Join Normal Form (PJ/NF), which is quite a
difficult concept to get your teeth around as its defined in terms of 'join
dependencies' as well as the usual 'functional dependencies' which define the
lower normal forms.

Ken Sheridan
Stafford, England
 
J

John W. Vinson

Trying to figure the tables and relations for the following scenario:

Many users. Many machines with many accounts per machine.
Users have access to certain accounts on certain machines

I am just learning db and relations, but I was thinking of two tables.

One table with user info & what machine and account they have access to on
that particular machine.

A second table with the server name and accounts on it.

This is the first I have tried more than one table and joining. Any
suggestions? Is there a better way?

Yes; since you have three kinds of Entities (Users, Machines, Accounts) you
need a table for each; and a fourth table to resolve the many-to-many-to-many
relationship between these.

Users
UserID
LastName
FirstName
<other biographical data and contact information>

Machines
MachineID
<information about the machine, e.g. human meaningful name, location, etc.>

Accounts
AccountNo <Primary Key>
AccountName

Assignments
MachineID <link to Machines>
AccountNo <link to Accounts, which account has access>
UserID <link to Users, which user has access>
 
V

vm

Thanks for the posts. I have used access before but only with single tables
where all data was standard and uniform. Every time I tried to do more - my
head would explode. I have a project now that will require more, so I have no
choice but to learn. I appreciate the suggestions. I have a lot of testing
and studying to do before I get understand to a point I can be useful. Thanks
again for the suggestions. I think it is what I needed to get me going..

vm
 
J

John W. Vinson

Thanks for the posts. I have used access before but only with single tables
where all data was standard and uniform. Every time I tried to do more - my
head would explode. I have a project now that will require more, so I have no
choice but to learn. I appreciate the suggestions. I have a lot of testing
and studying to do before I get understand to a point I can be useful. Thanks
again for the suggestions. I think it is what I needed to get me going..

Good on ya! and good luck.

Here are some additional resources that may help you over the nontrivial
learning curve into relational thinking. You'll find it extremely useful and
very logical once you get there.

Jeff Conrad's resources page:
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page:
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP):
http://allenbrowne.com/casu-22.html

MVP Allen Browne's tutorials:
http://allenbrowne.com/links.html#Tutorials
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top