Professional Documents
Culture Documents
2
© Pearson Education Limited 1995, 2005
Relational Model Terminology
Tuple is a row of a relation.
3
© Pearson Education Limited 1995, 2005
Alternative Terminology for Relational Model
4
© Pearson Education Limited 1995, 2005
Mathematical Definition of Relation
Consider two sets, D1 & D2, where D1 = {2, 4} and D2
= {1, 3, 5}.
Cartesian product, D1 D2, is set of all ordered
pairs, where first element is member of D1 and
second element is member of D2.
D1 D2 = {(2, 1), (2, 3), (2, 5), (4, 1), (4, 3), (4, 5)}
6
© Pearson Education Limited 1995, 2005
Relational Keys
Key plays an important role in relational database .It
is used for identifying unique rows from table. It also
establishes relationship among tables.
Superkey
Candidate Keys
Primary Key
Alternate Keys
Foreign Key
Composite Key
7
SuperKey
Superkey
– An attribute, or set of attributes, that uniquely
identifies a tuple within a relation.
8
© Pearson Education Limited 1995, 2005
Table: Employee
11 116 Anshika
12 117 Devanshi
15 118 Aditya
16 119 Arun
All of the following sets of super key are able to uniquely identify a row of
the employee table.
•{Emp_SSN}
•{Emp_Number}
•{Emp_SSN, Emp_Number}
•{Emp_SSN, Emp_Name}
•{Emp_SSN, Emp_Number, Emp_Name}
9
•{Emp_Number, Emp_Name}
Candidate Key
Candidate Key
– Superkey (K) such that no proper subset is a superkey
within the relation.
– In each tuple of R, values of K uniquely identify that
tuple (uniqueness).
– No proper subset of K has the uniqueness property
(irreducibility).
10
Table: Employee
11 116 Anshika
12 117 Devanshi
15 118 Aditya
16 119 Arun
11
Primary Key
Primary Key
– Candidate key selected to identify tuples uniquely within
relation.
The value of primary key should be unique for each row of the
table. The column(s) that makes the key cannot contain duplicate
values.
12
Table : STUDENT
Stu_Id Stu_Name Stud_Age
11 Deepak 20
12 Kavya 19
15 Mohit 22
16 Aman 23
13
Alternate Keys
Alternate Keys
– Candidate keys that are not selected to be primary
key.
14
Table: Employee
Emp_Id Emp_Number Emp_Name
11 116 Namita
12 117 Anju
15 118 Vaibhav
16 119 Prakhar
15
Foreign Key
Foreign Key
– Attribute, or set of attributes, within one relation that
matches candidate key of some (possibly same) relation.
16
Table :Course_enrolment Table: Student
BCS-13 101
101 Rupal 22
BCS-14 102
102 Shreya 26
BCS-15 101
BCS-16 102 103 Harshit 25
BCS-17 103 104 Shivam 21
BCS-18 102
17
Composite key
Any key such as super key, primary key, candidate key etc. can be called
composite key if it has more than one attributes.
18
Table :Sales
19
Integrity Constraints
Null
– Represents value for an attribute that is
currently unknown or not applicable for tuple.
– Deals with incomplete or exceptional data.
– Represents the absence of a value and is not the
same as zero or spaces, which are values.
20
© Pearson Education Limited 1995, 2005
Integrity Constraints
Entity Integrity
– In a base relation, no attribute of a primary
key can be null.
Referential Integrity
– If foreign key exists in a relation, either
foreign key value must match a candidate
key value of some tuple in its home relation
or foreign key value must be wholly null.
21
© Pearson Education Limited 1995, 2005
Integrity Constraints
General Constraints
– Additional rules specified by users or
database administrators that define or
constrain some aspect of the enterprise.
22
© Pearson Education Limited 1995, 2005