Professional Documents
Culture Documents
Chap05 Modified PDF
Chap05 Modified PDF
Chap05 Modified PDF
Data Manipulation:
Powerful operations (using the SQL language) are used to
manipulate data stored in the relations.
Data Integrity:
Facilities are included to specify business rules that
maintain the integrity of data when they are manipulated.
Relation
Definition: A relation is a named, two-dimensional table of
data
Table is made up of rows (records), and columns (attribute or field)
Requirements:
Every relation has a unique name.
Every attribute value is atomic (not multivalued, not composite)
Every row is unique (cant have two rows with exactly the same
values for all their fields)
Key Fields
Keys are special attributes/fields that may be used as:
Primary Key An attribute (or combination of attributes)
that uniquely identifies each row in a relation.
Examples include employee numbers, social security
numbers, Roll number etc. This is how we can
guarantee that all rows are unique
Foreign Key An attribute in a relation of a database
that serves as the primary key of another relation in
the same database and used to link or associates
both relations. It can also be defined as
Identifiers that enable a dependent relation (on the
many side of a relationship) to refer to its parent
relation (on the one side of the relationship)
Keys can be simple (a single field) or composite
(more than one field)
Faculty Name: Muhammad Aqeel
Primary Key
Foreign Key
Constraints
Constraints are used to maintain the accuracy and
integrity of data stored in database. There are different
types of constraints.
e.g. Domain Constraints, Entity Integrity, Referential
Integrity, etc.
Domain Constraints
Allowable values for an attribute. See Table 5-1
fields MUST have data
Action Assertions
Business rules. Recall from Ch. 4
Referential integrity
constraints are
drawn via arrows
from dependent to
parent table
10
(a) CUSTOMER
entity type with
simple attributes
11
12
15
Foreign key
18
Foreign key
19
New
Foreign key
Foreign key
intersection
relation
21
22
Resulting relations
23
Identifier
Assigned
25
26
27
(b) EMPLOYEE
relation with
recursive foreign
key
28
(a) Bill-of-materials
relationships (M:N)
(b) ITEM and
COMPONENT
relations
29
30
31
Supertype/subtype relationships
34
35
NORMALIZATION
Well-structured relation
A relation that contains minimal
redundancy and allows users to insert,
modify, and delete the rows in a table
without errors or inconsistencies.
Anomaly
An error or inconsistency that may
result when a user attempt to update a
table that contains redundant data. The
three types of anomalies are insertion,
deletion, and modification.
Faculty Name: Muhammad Aqeel
36
Example
Is this a relation?
Data Normalization
The process of decomposing
relations with anomalies to produce
smaller, well-structured relations.
A Primarily a tool to validate and improve
a logical design so that it satisfies certain
constraints that avoid unnecessary
duplication of data
40
41
Functional Dependency:
A constraint between two attributes or two sets of attributes.
For any relation R, attribute B is functionally dependent on
attribute A, if for every instance of A, the value of A uniquely
determines the value of B. It can be represented as
R: A B
For example
In student relation : Roll_No
Candidate Key:
An attribute, or combination of attributes, that
uniquely identifies a row in a relation. One of the
candidate keys will become the primary key
E.g. perhaps there is both credit card number and SS# in a
tablein this case both are candidate keys
Employee
Emp_ID
Emp_Name
Address
SSN
Qualification Contact_no
43
Surveys
5/22/200X
44
45
EmpID
46
EmpID
Name
EmpID
DeptName
CourseTitle
Salary
DateCompleted
47
Transitive Dependency:
A functional dependency between two (or
more) non-key attributes.
48
CustID Name
CustID Salesperson
CustID Region
All this is OK
(2nd NF)
BUT
CustID Salesperson Region
Transitive dependency
(not 3rd NF)
49
50
51
Relations in 3NF
Salesperson Region
CustID Name
CustID Salesperson
Now, there are no transitive dependencies
Both relations are in 3rd NF
52
4th NF
No multivalued dependencies
5th NF
No lossless joins
Domain-key NF
The ultimate NFperfect elimination of all possible
anomalies
53
55
(Delete Anomaly)
If we want to replace Hawking advisor with
Edward then we have to change in all rows (two)
(Update Anomaly)
A new Advisor Babbage for Physics can only
insert if we have at least one student who works
under his supervision.
(Insert Anomaly)56
Faculty Name: Muhammad Aqeel
57
58
59
60
61