Home » SQL & PL/SQL » SQL & PL/SQL » Understanding Primary Key/Composite Key
Understanding Primary Key/Composite Key [message #584737] Fri, 17 May 2013 06:45 Go to next message
Taha
Messages: 8
Registered: February 2009
Location: Karachi
Junior Member
Hi,

I am following Lynda Tutorial for Normalization. I have understand normalization but still there are few basic question that i want to ask here.
The core concept of primary key is that it uniquely identifies each record in the table, but here in the given below image the 'COURSE' field is repeating 'SQL101' value again and again but still the teacher in the video is calling it primary key and combination of date & Course column Composite key.
My Question here is that how can a field which vales are repeating can be called as Primary Key? Please explain.
./fa/10798/0/


Thanks
Taha.

[Updated on: Fri, 17 May 2013 06:45]

Report message to a moderator

Re: Understanding Primary Key/Composite Key [message #584738 is a reply to message #584737] Fri, 17 May 2013 06:48 Go to previous messageGo to next message
Littlefoot
Messages: 19680
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
COURSE can not be a primary key here, as you said - SQL101 violates it.

Combination of COURSE and DATE columns can be, and - in that case, that primary key is a composite (as it consists of 2 columns).
Re: Understanding Primary Key/Composite Key [message #584741 is a reply to message #584738] Fri, 17 May 2013 06:52 Go to previous messageGo to next message
Taha
Messages: 8
Registered: February 2009
Location: Karachi
Junior Member
so if Primary Key is a Composite Key then we can repeat its value ?
e.g:- the combination of COURSE and DATE have to be unique and they can repeat themselves in their fields but their combination have to be unique?
Re: Understanding Primary Key/Composite Key [message #584742 is a reply to message #584738] Fri, 17 May 2013 06:53 Go to previous messageGo to next message
cookiemonster
Messages: 11068
Registered: September 2008
Location: Rainy Manchester
Senior Member
If I had that in the database I would have two tables:
one with course and course title - pk course. The master list of courses
one with course, date, room, capacity etc - pk course and date - the list of when (and where) the courses are run.
Re: Understanding Primary Key/Composite Key [message #584743 is a reply to message #584741] Fri, 17 May 2013 06:54 Go to previous messageGo to next message
cookiemonster
Messages: 11068
Registered: September 2008
Location: Rainy Manchester
Senior Member
Taha wrote on Fri, 17 May 2013 12:52
so if Primary Key is a Composite Key then we can repeat its value ?
e.g:- the combination of COURSE and DATE have to be unique and they can repeat themselves in their fields but their combination have to be unique?

yes
Re: Understanding Primary Key/Composite Key [message #584745 is a reply to message #584743] Fri, 17 May 2013 06:59 Go to previous messageGo to next message
Taha
Messages: 8
Registered: February 2009
Location: Karachi
Junior Member
Thanks a lot for the help, 1 last question, Does Composite key can only be created in Foreign key Table? i.e i can not create Composite key in master table of Course.
Re: Understanding Primary Key/Composite Key [message #584747 is a reply to message #584737] Fri, 17 May 2013 06:59 Go to previous messageGo to next message
dariyoosh
Messages: 532
Registered: March 2009
Location: Iran / France
Senior Member
Taha wrote on Fri, 17 May 2013 13:45
Hi,

I am following Lynda Tutorial for Normalization. I have understand normalization but still there are few basic question that i want to ask here.


Hi,

Juste for information in orafaq Wiki there is a very good article about Normalization

Regards,
Dariyoosh
Re: Understanding Primary Key/Composite Key [message #584749 is a reply to message #584745] Fri, 17 May 2013 07:15 Go to previous messageGo to next message
cookiemonster
Messages: 11068
Registered: September 2008
Location: Rainy Manchester
Senior Member
Taha wrote on Fri, 17 May 2013 12:59
Thanks a lot for the help, 1 last question, Does Composite key can only be created in Foreign key Table? i.e i can not create Composite key in master table of Course.

With my example there is no point having a compostite key in the master table.
Other master tables may require one. It depends on the type of data you want to store, nothing more.
Re: Understanding Primary Key/Composite Key [message #584752 is a reply to message #584749] Fri, 17 May 2013 07:34 Go to previous messageGo to next message
Taha
Messages: 8
Registered: February 2009
Location: Karachi
Junior Member
cookiemonster wrote on Fri, 17 May 2013 17:15
Taha wrote on Fri, 17 May 2013 12:59
Thanks a lot for the help, 1 last question, Does Composite key can only be created in Foreign key Table? i.e i can not create Composite key in master table of Course.

With my example there is no point having a compostite key in the master table.
Other master tables may require one. It depends on the type of data you want to store, nothing more.


ok, Thanks a lot !! Smile
Re: Understanding Primary Key/Composite Key [message #584753 is a reply to message #584747] Fri, 17 May 2013 07:34 Go to previous messageGo to next message
Taha
Messages: 8
Registered: February 2009
Location: Karachi
Junior Member
dariyoosh wrote on Fri, 17 May 2013 16:59
Taha wrote on Fri, 17 May 2013 13:45
Hi,

I am following Lynda Tutorial for Normalization. I have understand normalization but still there are few basic question that i want to ask here.


Hi,

Juste for information in orafaq Wiki there is a very good article about Normalization

Regards,
Dariyoosh


Thanks for the Article Smile
Re: Understanding Primary Key/Composite Key [message #584758 is a reply to message #584753] Fri, 17 May 2013 07:54 Go to previous messageGo to next message
Michel Cadot
Messages: 59407
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And, one step further, to be normalized, "CourseTitle" should not be in this table but in a "Courses" table wit primary key "Course" and, at least, the "CourseTitle" one (which can also be unique).

Regards
Michel
Re: Understanding Primary Key/Composite Key [message #584759 is a reply to message #584758] Fri, 17 May 2013 07:56 Go to previous messageGo to next message
Littlefoot
Messages: 19680
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
As this is a "Lynda Tutorial for Normalization", maybe that screenshot displays the starting point, i.e. the way your tables shouldn't look like. Then, as the tutorial goes on, the EVENTS table gets normalized.
Re: Understanding Primary Key/Composite Key [message #584894 is a reply to message #584759] Mon, 20 May 2013 06:55 Go to previous message
Taha
Messages: 8
Registered: February 2009
Location: Karachi
Junior Member
Thanks !! Smile
Previous Topic: Truncate Master Table Issue
Next Topic: Join in Insert
Goto Forum:
  


Current Time: Tue Oct 21 00:34:47 CDT 2014

Total time taken to generate the page: 0.14121 seconds