MedVision ad

Ipt (1 Viewer)

jpk

Member
Joined
Sep 15, 2003
Messages
154
Help with keys

HI
i was wondering if any1 can help me out with keys.
I read the heinman textbook but i still dont get wat the difference between all of them are....

-single key
-primary key
-composite key
-secondary key

and also wats a foreign key?
 
Last edited:

Huy

Active Member
Joined
Dec 20, 2002
Messages
5,240
Gender
Undisclosed
HSC
N/A
jpk, the search button is there for a reason ;)

There are a fair few threads about the same question, right on the same page, listing all the IPT threads.

Question PLEASE ANSWER :)
http://www.boredofstudies.org/community/showthread.php?s=&threadid=12580

1NF and DKNF (foreign key question)
http://www.boredofstudies.org/community/showthread.php?s=&threadid=14106

Primary Key
http://www.boredofstudies.org/community/showthread.php?s=&threadid=244

keys
http://www.boredofstudies.org/community/showthread.php?s=&threadid=2040

The very first thread has all the relevant details, but you might want to read through the others as well. :)

Kieransgirl summed it up nicely at the end
Originally posted by kieransgirl
primary key- a field which is unique to t he table
secondary key- a field which is in a number of the tables (useful for searching)
foreign key- a primary key in another table
See my post in that thread ("question please answer").

It covers all your keys, as best I could.
 
Last edited:

jpk

Member
Joined
Sep 15, 2003
Messages
154
thx
BUt i know definition and all... but i want to know wat itactually is
can some1 give me an example for a databse for say skool?
 

Huy

Active Member
Joined
Dec 20, 2002
Messages
5,240
Gender
Undisclosed
HSC
N/A
Originally posted by jpk
thx
BUt i know definition and...
That's where the IPT exam stops :D
Basically that's all you need to know, define a couple of different types of keys, as far as I can tell.
can some1 give me an example for a databse for say skool?
Examples:

Primary - StudentID
Single - ClassName
Composite - StudentClassID
Secondary - TeacherID
Foreign - ClassID

That's the best I can explain it.

:)
 

jpk

Member
Joined
Sep 15, 2003
Messages
154
so can composite key be something like a link between class ID to STudient ID??
i always thought it was a link from same fields. EG Class ID to Class ID
 

Huy

Active Member
Joined
Dec 20, 2002
Messages
5,240
Gender
Undisclosed
HSC
N/A
Originally posted by jpk
so can composite key be something like a link between class ID to STudient ID??
i always thought it was a link from same fields. EG Class ID to Class ID
Originally posted by Huy
Composite key - created by joining 2 or more fields together.
You will only need a composite key if you have a field which cannot be guaranteed to be unique, so you combine other fields together (to form a composite key), which is definately unique.

For example "JPK.BOS.2003.IPT"
It ensures that you end up with a unique field.

E.g. anyone can have "BOS" in their field, or "2003" or even "IPT"

But if you combine all 3, as well as your DOB or any other field, it becomes unique.

That's the purpose of having a composite key, it doesn't link to any other entities like you are suggesting, (ClassID to ClassID).

ClassID might be an entity, with ClassID being another field, within that same entity.

A relationship does not exist however, between (say) "JPK.BOS.2003.IPT" and "ClassID" because the composite key was only created to be unique (an identifier).

You are getting confused between Entity-Relationship-Diagrams (ERD's or schemas) and the purpose of having keys.

To answer your question, no. A composite key cannot be "something like a link between ClassID and StudentID" - this is a relationship (be it one to one, one to many, many to many).

"A link from the same fields" happens to be a relationship, not a composite key.

:)
 

jpk

Member
Joined
Sep 15, 2003
Messages
154
ah thx alot i had the idea of keys all wrong...
and wats the difference between single key and primary key?? and also some1 told me that some of the keys are foreign keys?
im still confused??!?
 
Last edited:

Huy

Active Member
Joined
Dec 20, 2002
Messages
5,240
Gender
Undisclosed
HSC
N/A
Originally posted by jpk
wats the difference between single key and primary key?? and also some1 told me that some of the keys are foreign keys?
im still confused??!?
Single key = contains data in the field that is unique

Primary key IS a single key and must have a value.

Foreign key IS a primary key, from another table.

:)
 

Huy

Active Member
Joined
Dec 20, 2002
Messages
5,240
Gender
Undisclosed
HSC
N/A
Originally posted by jpk
wat do u mean by value???
It can't be null, you can't leave it blank.

You have to have a data entry in the field. :)
 

jpk

Member
Joined
Sep 15, 2003
Messages
154
so signel key and primary key are basically same.
since all fields always have value
 

Huy

Active Member
Joined
Dec 20, 2002
Messages
5,240
Gender
Undisclosed
HSC
N/A
Yes, in effect.

Primary keys are single keys.
But single keys are not primary :)

Single keys and primary keys have to have values. But you can't have multiple primary keys ;)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top