UNIT 18 M1 (M 1) - Explain referential integrity and the purpose of primary keys in building the relationships between tables
Referential
integrity helps to keep records between linked tables consistent and matched when
using foreign keys. An example of a table of the courses and a table of enrolments,
if you link them and assign students to each course record, the referential
integrity is used to ensure the records correspond between the tables. Here is
another example; you will not be able to edit a record to the enrolment table
that does not use a valid record from the course table. It also manages updates
between the linked tables, for example if a record is removed from the course
table it will update the information in the enrolment and student table linked
to it. This can alert someone if they try to delete a record which is very
helpful.
Primary keys
A primary
key is a relational table that uniquely identifies each record in the table.
These unique attributes could be normal ones but they have to be something that
is guaranteed not to be the same with anything else. Primary keys tend to be at
the top of every table which can only be in one table but yet may be able to be
linked to other tables to make a record of it. Imagine that there is a
‘student’ table that holds a record of each student at the college. The
students unique ID number would be a great choice for a primary key in the
‘students’ table. If the students first and last name were to be used as a
primary key then that would not be a good choice as there might be more than
one student that has the exactly the same name.
Foreign keys
The whole
point of the foreign key is used to link tables together in a table that
provides a connection between data for a relationship of the tables to be made.
The foreign keys act as a cross-reference between tables due it referencing the
primary key to another table, which then establishing a link between them. They
are different types of relationships like ‘1-1’,1-many’, ‘many-many’ and
‘many-1’. Here are the examples:
1-1 –
One passport to one passport owner.
1-many – One
person may have many shoes (more than 2 pairs of shoes).
Many-many- A
number of siblings have a number of cousins
Many-1- One
dad may have many children.
At the first heading you wrote "Relational" and not "referential"
ReplyDeleteyou mean, the subheading?
Deleteyou mean, the subheading?
DeleteThis comment has been removed by the author.
DeleteREFER!!!!!!!!!!
ReplyDeleteExplains really well how it works, thank you helped a lot
ReplyDelete