Glasgow University Bioinformatics forum

Glasgow University Bioinformatics forum, for the MRes bioinformatics students of the University of Glasgow
 
HomeHome  ­FAQFAQ  ­SearchSearch  ­MemberlistMemberlist  ­UsergroupsUsergroups  ­RegisterRegister  ­Log inLog in  
Post new topic   Reply to topicShare | 
 

 Question about our ISD3 exercise

View previous topic View next topic Go down 
AuthorMessage
markj



Posts: 69
Join date: 2008-09-23

PostSubject: Question about our ISD3 exercise   Tue Oct 28, 2008 6:46 pm

Hi guys,

I did not understand key very well. In our handout, it is said key should not duplicate. but in our exercise, why AccNo can be duplicated and is also a key?
Back to top Go down
View user profile
Nico



Posts: 48
Join date: 2008-09-18

PostSubject: Re: Question about our ISD3 exercise   Wed Oct 29, 2008 12:11 am

You have to distinguish primary key and foreign key.



Primary means, one data of one column (column which is defined as a primary key) or a set of data (one row) cannot be duplicated within this column. for instance, if name is a primary key you can have:

Code:
name                    is clever?
weij                      yes
nicolas                  no


but you cannot have:

Code:
name                  is clever?
weij                    yes
weij                    maybe
nicolas                no



I do not have microsoft access right now, but i do not think one account number, let say 00580 appears two times in the same column "account number" of the same table.


After that you have the "foreign key":
For instance, name will be a primary key in the first table "name and clever", and a foreign key in the second table "name and module":

Code:
name(primary key)          is clever?
weij                                          yes
nicolas                                      no

name(foreign key)                  module
weij                                          ISD
weij                                          sequence analysis under unix
nicolas                                      ISD
nicolas                                      sequence analysis under unix


as you can see name is duplicated in the second table because it is a foreign key but not in the first one. However, it is a key (foreign key) because you have put a link between the two tables through the "name" attribute; Hence, name is a key in the second table and is duplicated. Very Happy Very Happy

if you are still struggling, i found this link, maybe there is a better website, have a look:

http://www.databasedev.co.uk/primary_foreign_key_constraints.html
Back to top Go down
View user profile
markj



Posts: 69
Join date: 2008-09-23

PostSubject: Re: Question about our ISD3 exercise   Wed Oct 29, 2008 1:00 pm

Nico,

Thanks very much. I think I've understanded better after read in the website you provided.

In the case which I asked, both columns 'AccNo' and 'CustId' were defined as one primary key

Many thanks again

cheers Razz lol! Very Happy

Nico wrote:
You have to distinguish primary key and foreign key.



Primary means, one data of one column (column which is defined as a primary key) or a set of data (one row) cannot be duplicated within this column. for instance, if name is a primary key you can have:

Code:
name                    is clever?
weij                      yes
nicolas                  no


but you cannot have:

Code:
name                  is clever?
weij                    yes
weij                    maybe
nicolas                no



I do not have microsoft access right now, but i do not think one account number, let say 00580 appears two times in the same column "account number" of the same table.


After that you have the "foreign key":
For instance, name will be a primary key in the first table "name and clever", and a foreign key in the second table "name and module":

Code:
name(primary key)          is clever?
weij                                          yes
nicolas                                      no

name(foreign key)                  module
weij                                          ISD
weij                                          sequence analysis under unix
nicolas                                      ISD
nicolas                                      sequence analysis under unix


as you can see name is duplicated in the second table because it is a foreign key but not in the first one. However, it is a key (foreign key) because you have put a link between the two tables through the "name" attribute; Hence, name is a key in the second table and is duplicated. Very Happy Very Happy

if you are still struggling, i found this link, maybe there is a better website, have a look:

http://www.databasedev.co.uk/primary_foreign_key_constraints.html
Back to top Go down
View user profile
 

Question about our ISD3 exercise

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
Glasgow University Bioinformatics forum :: IT Strand :: Information Systems and Databases-
Post new topic   Reply to topic