If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Clairification on 3NF

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-07, 03:11
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Clairification on 3NF

Can someone please tell me if I have a transitive dependancy here. I would like to have one table with mfgr, model number and serial number as non-key fields with a surrogate key.

I think that I possibly have a transitive dependancy between mfgr and serial number and most certainly between mfgr and model number but I am not positive.


Thanks.

Frank
Reply With Quote
  #2 (permalink)  
Old 08-25-07, 04:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
pretty hard to tell just from the names, but yeah, i would say you're right

try this: given a specific value of the PK, this determines the values of all non-key attributes, right?

so for a specific value of the PK, if i were to change the value in one of the non-key attributes, would the data still be the same in the other non-key attributes? if i changed the mfgr, would the model number still be valid?

by comparison, consider a table for employees, with empno as the PK, and let's take a specific value of the PK, the one corresponding to you

if i changed the phone number for you, would that require a change to your address? a change to your hatsize? no, because all these non-key attributes are independently dependent on the value of the PK, namely you
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937; 08-25-07 at 04:16.
Reply With Quote
  #3 (permalink)  
Old 08-25-07, 04:20
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by r937
pretty hard to tell just from the names, but yeah, i would say you're right

try this: given a specific value of the PK, this determines the values of all non-key attributes, right?

so for a specific value of the PK, if i were to change the value in one of the non-key attributes, would the data still be the same in the other non-key attributes? if i changed the mfgr, would the model number still be valid?
Hi Rudy. Thanks for the reply.

The PK will be an auto-incrementing surrogate. So if a value was changed in one of the non-key fields, it would affect the the other fields as well. Unless I am misunderstanding your question. Here would be some sample data.

Code:
mfgr        model    serial     PK
motorola   X563    12dsd     1
motorola   r2dd     jo445     2
I have a pic I am going to post. brb.

Last edited by Frunkie; 08-25-07 at 04:32.
Reply With Quote
  #4 (permalink)  
Old 08-25-07, 04:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
okay, let's use an example

for PK=1, if i changed the serial number to XP428-834, it is still model=X563?

answer: prolly not

it looks like model is dependent on serial, and mfgr on model

i.e. it's not 3NF
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-25-07, 04:38
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
That is what I figured. It is not in 3NF. Ok.. So here is a jpg of the changes I have made so far..

We are talking about the company_Equipment tables. I have taken serial_Number out and I am debating whether to put mfgr in its own table.
Attached Thumbnails
Clairification on 3NF-11.jpg  
Reply With Quote
  #6 (permalink)  
Old 08-25-07, 04:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
so a piece of company equipment cannot be entered into your database unless it is already loaned out to a specific employee? what happens when he returns it? you won't allow company_equipment.employee_number_seq to be null, so what do you put there if the piece of equipment is currently not loaned out?

and what's the purpose of naming your columns like company_equipment_status? what's wrong with just status? you particularly enjoy typing extra needless characters?

and how come a single piece of company equipment can have multiple serial numbers?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 08-25-07, 04:59
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by r937
so a piece of company equipment cannot be entered into your database unless it is already loaned out to a specific employee? what happens when he returns it? you won't allow company_equipment.employee_number_seq to be null, so what do you put there if the piece of equipment is currently not loaned out?

and what's the purpose of naming your columns like company_equipment_status? what's wrong with just status? you particularly enjoy typing extra needless characters?

and how come a single piece of company equipment can have multiple serial numbers?
That is correct. The only time that a pice of equipment would be entered into the database is if it has been loaned out.

When he returns it, the date is entered into the date_In field. I know that these tables have some issues. I am trying to work them out.. I am all ears if you have a better way to model this.

LOL.. I hate typing! Ok, here is where being a nubie comes into play. I type the prefixes such as customer_Status because when I am joining the tables back together and I am viewing the results, the tables that have the same names such as "status" are null. I am thinking that may be because the names are the same. Can I use an alias to fix that?

No, I don't see that a single piece of equipment can have multiple serial numbers. Actually, your correct.. What do you suggest. I am really out of answers.
Reply With Quote
  #8 (permalink)  
Old 08-25-07, 05:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
so if a piece of equipment has been loaned out, and then comes back in, it's not still loaned out, is it? so what do you do if it has to be loaned out again?

using column aliases in your queries for specific reporting purposes sounds like a much more sensible approach than bastardizing the column names in the table

as for the serial number, i don't know your equipment but i would guess that the serial number is actually a candidate key for the equipment

can two pieces of equipment have the same serial number?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-25-07, 05:10
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by r937
so if a piece of equipment has been loaned out, and then comes back in, it's not still loaned out, is it? so what do you do if it has to be loaned out again?

using column aliases in your queries for specific reporting purposes sounds like a much more sensible approach than bastardizing the column names in the table

as for the serial number, i don't know your equipment but i would guess that the serial number is actually a candidate key for the equipment

can two pieces of equipment have the same serial number?
Well, if the piece of equipment comes back, it would be reflected in the date_In field then if it were loaned back out, the equipment would be re-entered into the db under a different person. Is there a better way to do that? Ywo pieces of equipment would not have the same serial number.

Ok.. I hate bastardizing anything.. I have to go back through the database and rename all of those columns.

The serial number is the candidate key but the reason I gave it a surrogate key was because the user may not know what the serial number is. Does that make sense?

EDIT: Nevermind. I understand what you are saying about the serial number.. Ok, I need to dump the surrogate..

I have a question regarding the company_Vehicle tables. The vehicle can be loaned out during a shift and I need to tie that table to the employee. Vehicles are equipment as well so shouldn't that be somehow tied to the equipment table?

Last edited by Frunkie; 08-25-07 at 05:20.
Reply With Quote
  #10 (permalink)  
Old 08-25-07, 06:01
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
What I did to circumvent a single piece of equipment from having a second serial number attached to it was to drop the serial number table and add serial_Number to the equipment table as its PK.

I am seeing that now, with this change, it will be impossible to add a piece of equipment that *does not* have a serial number. What would be the best way around this?

Thanks,

Frank
Reply With Quote
  #11 (permalink)  
Old 08-25-07, 07:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
if you dump the surrogate and make serial number the PK, then you can never have a piece of equipment without a serial number

you could give the serial number a unique constraint

but then you'd only ever be able to loan it out once


ain't data modelling fun?

do you see now why so many programmers just throw their hands up and forget about primary keys and foreign keys?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 08-25-07, 10:45
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
What on earth leads you to suspect that device serial numbers are unique? IP Addresses are supposed to be unique, and they are unique on any given VLAN, but do you have any concept of how many devices have the address of 192.168.1.100 in the world? VIN numbers are supposed to be unique too, but I happen to own a vehicle that shares its VIN with at least one other vehicle registered in the United States (this is ugly, do NOT try it at home).

The only "unique" that I will ever depend on again is when I can define something to be unique, such as a GUID or (under duress) a sequence number with a unique constraint.

-PatP
Reply With Quote
  #13 (permalink)  
Old 08-25-07, 11:06
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by Pat Phelan
What on earth leads you to suspect that device serial numbers are unique?
who, me??

" ... on earth?" sure, your point may have merit

but actually, within a given app, where we are dealing with pieces of equipment owned by a given company, it's not unreasonable to have unique serial numbers

in fact, i've worked for more than one company where they inventoried every single piece of equipment in the company with "asset tags" which had unique serial numbers (once as part of a Y2K initiative)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #14 (permalink)  
Old 08-25-07, 11:12
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by Pat Phelan
such as a GUID or (under duress) a sequence number with a unique constraint.
In SQL Server the GUID is only guaranteed unique if generated by two machines on the same network. I hope you don't have any rogue servers knocking around on different netwroks on remote sites

I would agree with Rudy that you need to measure this against your domain. I have (in my much more limited experience naturally) experienced far more problems from absent unique constraints than present ones.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #15 (permalink)  
Old 08-25-07, 12:26
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Statistically speaking there are 2 other people who share the same DNA as you!
__________________
George
Twitter | Blog
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On