Notes Database Systems
Notes Database Systems
D A T A B A SE
SY ST E M S
WRITTEN BY
DATA INFORMATION
Data is raw facts and figures. Information is processed form of data.
Information is always useful for decision
Data is not useful for decision making.
making.
Information is output of the computer
Data is input for the computer system.
system.
Data is huge in volume. Information is summarized.
Information can be reproduced when
It is nearly impossible to reproduce data.
required.
Data does not depend upon information. Information depends upon data.
Database approach is a
computer-based method to handle
business application. It uses
databases to record and maintain
data.
A database is an organized
collection of data stored in related
tables. It stores data in efficient and
compact manner. It is created,
manipulated and maintained using a
database program.
The database program is also
known as database management system (DBMS). The structured query language is used
to interact with databases through DBMS.
4. DATA INTEGRATION
Data integration means that the data is logically centralized while it may
actually be stored at different locations.
5. DATA INTEGRITY
Data integrity means reliability and accuracy of data. In database approach, it is
very easy to apply different constraint on data. For example, it is very easy to ensure that
the marks of a student must be numeric or the roll number is not duplicated.
6. TRANSACTIONAL SUPPORT
A transaction is a series of database operations to a complete a task. In database
approach, the DBMS automatically ensures transactional properties like atomicity,
consistency, isolation and durability. These properties are commonly known as ACID
properties.
7. DATA SECURITY
In database approach, the DBMS provides authorized access to data. For
example, it is very easy to prevent one user from deleting data while allowing the other.
8. DATA SHARING
In database approach, the data is logically centralized. Therefore, the data sharing
is very high. For example, admission department and examination department can share
data of students stored at a central place.
9. LESS DEVELOPMENT TIME
In database approach, each new application shares data stored at a central place.
The new applications can be developed easily without designing their separate data files.
Therefore, it takes less time to develop new applications.
10. EASIER PROGRAM MAINTENANCE
In database approach, all applications access data stored at a central place.
Therefore, it is easier to modify applications when user requirement are changed.
organization has to hire experienced and skilled application programmers and database
administrators at high wages.
3. COST OF DATA CONVERSION
The conversion of data and from file processing system to a database system is
difficult and time consuming. Therefore, the organization has to hire technical persons like
application programmers and database administrators at high wages.
4. DATABASE FAILURE
In database approach, the data is centralized at one place. If the database is
unavailable due to power failure or any other issues then everyone suffers.
5. COMPLEXITY AND PERFORMANCE
The databases should be carefully designed and develop. A poorly designed
database may not satisfy the user requirements. In some cases, it may be less efficient
than file processing system.
4) WHAT ARE FILE PROCESSING SYSTEM AND DATABASE APPROACH? WHAT ARE
THE DIFFERENCES BETWEEN FILE PROCESSING APPROACH AND DATABASE
APPROACH?
DATABASE APPROACH
FIELD
RECORD
TABLE
DATABASE
FIELD
Field is the smallest unit of data item about an object. It is used to store a single piece
of data about something. For example, name and class are fields of a student.
Field
RECORD
Record is a collection of related fields about an object. It is used to store complete
information about something. It is stored as row in the table. For example, (102, M. Subhan,
[Link]., 0321-1234567) is a record of a student.
TABLE
databases. All of the data is stored in tables. All operations are performed on tables. The
results of all operations are returned as tables.
A table consists of rows and columns. Each row represents a record. Each column
represents a field. A database can have any number of tables as required.
DATABASE
DATABASE SYSTEM
DATABASE ARCHITECTURE
A complex database can consists of thousands of data items. These data items may
be accessed by thousands of users. The database designer divides these users into user-
groups. He allows each user-group to use their relevant parts of the database.
The way in which database designer organizes data into different user-groups is
called database architecture. The most common database architecture is three-level
architecture.
DATABASE SCHEMA
It is important to note that the data in the database changes frequently, while the plans
or schemes remains the same over a long period of time.
The database plans consists of types of entities about which data is stored in the
database, the relationships between these entities and the way in which the relationship
between entities are expressed. The plan or scheme of the database is knows as schema.
Database schema describes structure of a particular database. It usually remains
same while the data stored in the database is modified regularly.
Database schema stores the description of all data structures used in the database.
These descriptions can be anything from an entity to the whole organization. It also stores
various constraints applied on data.
All data descriptions and constraints are called metadata i.e. data about data. The
database schema is also called intension of the database.
DATABASE INSTANCE
The actual data stored in a database at any time is called database instance. The
database instance is modified as a result of day-to-day operations performed on the
THREE-LEVEL ARCHTITURE
The data is stored as binary numbers inside the computer. It is difficult to work with
data at this level. Three-level architecture provides data abstraction. The objective of three-
level architecture is to separate each user’s view of the database from physical
representation of the database.
The Three levels are different descriptions of the same data at different levels. It was
proposed by SPARC (ANSI) in 1975. The three levels are external level, logical level and
physical level.
The way in which different user-groups see stored data is called external level.
The way in which all entities, attributes and their relationships are described is
called logical level.
The way in which data is actually stored on physical storage device is called
internal level.
1. EXTERNAL LEVEL
The way in which different user-groups see the stored data is called external level.
The external level is described using one or more external views (external schemas).
Each external view describes part of the database which is relevant to a particular
user-group. It hides rest of the database from that user-group. External level is a
description of how the data is viewed by the end-users.
For example, a user may see student’s roll number and date-of-birth but cannot
see his telephone number.
Furthermore, different external views may present same data in different formats.
For example, in one external view the date may be displayed in (dd/mm/yyyy) format and
in another external view it may be displayed in (yyyy/mm/dd) format.
It is important to note that an external view may contain a data item that is actually
not stored in the database. For example, it may display the age of a person while date of
birth is actually stored.
2. CONCEPTUAL LEVEL
The way in which all entities, attributes and their relationships are described is
called conceptual level or conceptual schema.
A conceptual schema describes the structure of whole database. Conceptual
schema hides the details of physical storage structures and concentrates on describing
entities, attributes and their relationships. It also describes security and integrity
constraints of entire database. Conceptual schema is a description of what data is stored
in the database.
It is important to note that external views are extracted from conceptual schema. It
is done by selecting entities, attributes and their relationships that are visible in a
particular external view.
There is only one conceptual schema for a particular database.
3. INTERNAL LEVEL
The way in which data is actually stored on physical storage devices is called
internal level.
Internal level describes physical storage structures of the database. The internal
schema is a description of how database is physically represented on the storage
devices.
The internal schema provides definitions of the stored records, methods of
representation, data fields, indexes and hashing schemes. It also describes data
compression and encryption techniques.
It is important to note that three schemas are only descriptions of the data; the data
that actually exists is the data at physical level only.
MAPPING
DATA INDEPENDENCE
Data independence is one of the main objectives of using database approach. Data
independence means that the application programs or physical implementation can be
changed without changing the other.
There are two types of data independence. These are physical data independence
and logical data independence.
1. PHYSICAL DATA INDEPENDENCE
Physical data independence means that the physical schema of the database can
be changed without changing the logical schema. The DBMS hides such changes in
physical schema. Therefore, the external views and application programs will not be
changed too.
The changes that can be made in physical schema without affecting the logical
schema are as follows:
i. Adding new indexes
ii. Changing the file organization
iii. Changing the access method
iv. Changing the hashing algorithms
v. Changing the storage structure or storage media
2. LOGICAL DATA INDEPENDENCE
Logical data independence means that the logical schema of the database can be
changed without changing the external views. For example, if a new data item is added to
logical schema, the existing external views or application programs will only be changed if
they have to display the newly added data item.
The changes that can be made in logical schema without affecting the existing
external views or application programs are as follows:
i. Adding new entities
ii. Adding new attributes
iii. Adding new relationships
iv. Changing the data type of an attribute
6. CONCURRENCY SUPPORT
There may be a situation when the same data is accessed by more than one user
simultaneously. Database management system ensures concurrent access to the same
data. It handles all the problems that may occur due to concurrent access to the data.
7. USER ACCESSIBLE CATALOGUE / DATA DICTIONARY
Data dictionary is a repository of metadata. It contains names and descriptions of
tables and fields. It also contains information about data types, field lengths and integrity
constraints.
The information about end-users and their rights is also stored in the data
dictionary. Database management system provides access to the data dictionary.
Database administrators use data dictionary to control and manage the database.
8. DATA COMMUNICATION SUPPORT
Data is logically centralized in the database. Therefore, database is commonly
stored on servers. The users access data using computer network.
All communication with the database is managed by data communication
manager (DCM). DCM is not a part of the database management system. The database
management provides facilities to work with DCM so that the data can be accessed by
the users.
12) WHAT IS DATA DICTIONARY? ALSO DISCUSS ITS TYPES AND USES?
DATA DICTIONARY
Data dictionary is file or set of files that contains metadata about the database. In a
relational database, a data dictionary contains following things:
Names of all tables in the database and their owners
Names and descriptions of all the fields in tables
Names of all indexes and their related columns
Integrity constraints defined on the tables like primary keys, foreign keys,
relationships etc.
Information about end-users and their rights
In relational databases, the DBMS software needs data dictionary to access the data.
The data dictionary is used as a tool for communication between database designers and
end-users. It is also used by database administrators to control and manage the database.
There are two types of data dictionaries. These are integrated data dictionary and free
standing data dictionary.
1. INTEGRATED DATA DICTIONARY
Integrated data dictionary is a part of database management system. It is not only
17 Prof. M. Fahim, Govt. Graduate College, Gulberg, Lahore. 0300 – 774 25 26
[Link]. COMPUTER STUDIES
used during design and development of the database but it is also used every time a user
accesses the database.
Integrated data dictionary is automatically updated by DBMS whenever the
database schemas are modified. Therefore, it always has the latest information about
database schemas or structure of the database.
In relational databases, the data dictionary is integrated and active. It means that
the DBMS checks the data dictionary whenever the database is accessed.
2. FREE STANDING DATA DICTIONARY
Freestanding data dictionary is not a part of the DBMS. It is only used during
design and development of the database. It can be a third party product. It can also be a
simple file containing information about structure of the database.
Free standing data dictionary is developed by the database designer or database
administrator. It needs to be updated whenever structure of the database is modified.
Therefore, it may not have the latest information about the structure of database.
DATA MODEL
Data model is an abstraction of real world entities and their relationships. It defines
how data elements are connected to each other. It also defines how data is stored and
processed.
Data model is a collection of tools that are used to describe a database schema.
These tools are used to describe entities, their relationships, integrity constraints, storage
and processing of data.
The difference between data model and a database schema is that data model is a
collection of tools that are used to describe structure of a database while a database schema
describes the structure of a particular database.
Dr. E.F. Codd presented relational data model in June 1970. It is the most widely used
data model for storage and processing of data. In relational model, all of the data is stored in
relations (tables). A table consists of rows and columns.
An important characteristic of the relational model is the usage of keys. The keys are
specially designated columns within a relation. These columns are used to order data or
relate data with the data stored in other relations.
The relational model describes a set of rules to enforce data integrity. These rules are
known as integrity constraints. It also defines how the data is to be manipulated. It further
defines a special feature called normalization. The normalization reduces data redundancy
and removes database anomalies.
RELATIONAL DATA MODEL TERMINOLOGIES / CONCEPTS
Following are some important concepts of relational data model:
1. TABLE / RELATION
Table or relation is a fundamental concept in relational data model. All of the data
is stored in tables. A table consists of rows and columns. Each table stores data about a
particular entity. A database can have any number of tables.
2. TUPLE
A single row in the table is called tuple or record. It is a collection of related data
items about a particular object. A table can have any number of tuples but there are no
duplicate tuples in a relation.
3. ATTRIBUTE
The characteristics of an entity are called its attributes. The values of a particular
attribute are stored in a particular column. The attributes are also called fields. Each
relation can have any number of columns but there are no duplicate columns in a relation.
4. DOMAIN OF ATTRIBUTE
The set of all possible values for a particular attribute is called its domain. For
example, marks of a student can be a single value from 0 to 100. The set of all values
from 0 to 100 is called domain of marks.
5. KEY ATTRIBUTE OR IDENTIFIER
An attribute that have unique values for each tuple in the relation is called key
attribute or identifier. If there is no such attribute then combination of attributes is used as
key or identifier.
6. DEGREE OF TABLE
The number of columns in a table is called its degree. The degree of a table is
changed when a columns is added or removed from the table.
7. CARDINALITY OF TABLE
The number of rows in a table is called is called its cardinality. The cardinality of
table is changed when a row is inserted or deleted from the table.
14) WHAT IS DATA FLOW DIAGRAM (DFD)? DISCUSS DIFFERENT ELEMENTS OF DATA
FLOW DIAGRAM?
Data Flow Diagram (DFD) is a graphical tool that shows flow of data within the
system. It describes how data is processed by a system in terms of inputs and outputs. It
focuses on flow of data, where data comes from, where it goes and how it gets stored.
15) WHAT IS DATA FLOW DIAGRAM (DFD)? DISCUSS DIFFERENT ELEMENTS OF DATA
FLOW DIAGRAM?
16) EXPLAIN THE STEPWISE PROCEDURE FOR CREATING A DATA FLOW DIAGRAM
WITH AN EXAMLE?
A student (EE) sends in an application form (DF) containing his/her personal details
and desired course.
The university checks (P) whether the course is available.
If the course is available then the student is enrolled (P) in the course, and the
university confirms (P) the enrollment by sending a confirmation letter (DF) that
he/she is registered for the course.
Or if the course is unavailable the student is sent a rejection letter (DF).
Note: The University, or more specifically the administration section is the system that
is being modeled.
1. CONTEXT DFD
External Entity – Student
Process – Student Administration Application Processing
Data Flows – Application Form, Confirmation Letter, Rejection Letter
2. LEVEL 0 DFD
External Entity – Student
Processes – Check Course Availability, Enroll Student, Confirm Registration
Data Flows – Application Form, Course Details, Course Enrolment Details,
Student Details, Confirmation/Rejection Letter
Data Stores – Courses, Students
ENTITY-RELATIONSHIP MODEL
It is important to note that the term entity is used for entity type, entity instance and
entity set. The context in which the term entity is used explains its meanings.
ENTITY TYPE
The description of an entity is called entity type. An entity is described by its
attributes. For example, STUDENT and TEACHER entities are described using
their attributes as follows:
STUDENT (RollNo, SName, Class, DOB, TelephoneNo, Address)
TEACHER (TeacherId, TName, Subject, Qualification, Address)
ENTITY INSTANCE
Anything that exists according to the description of a particular entity type is
called its entity instance.
For example, a person having attributes (123, M. Rayyan, 1st Year, 07-04-
1997, 0333-1234567, Pak Colony Multan) is an instance of STUDENT entity type.
Similarly, a person having attributes (123, M. Subhan, Computer Science,
MPhil, Islampura Lahore) is an instance of TEACHER entity type.
ENTITY SET
Set of all entity instances of the same type is called entity set. For example,
set of all entity instances of STUDENT entity is a STUDENT entity set.
Similarly, set of all entity instances of TEACHER entity is also a TEACHER
entity set.
STRONG ENTITY
An entity that has its own identifier is called strong entity. For example,
LOAN entity has an attribute LoanID that has unique values for each LOAN
instance so LoanID can be used as identifier. Therefore, LOAN is a strong entity.
It is also said that an entity whose instances can exist independently is
called strong entity.
WEAK ENTITY
An entity that does not have its own identifier is called weak entity. The
instances of a weak entity are identified by the identifier of a strong entity.
For example, the loan is returned in installments. Each INSTALLMENT
instance is identified by the identifier of LOAN entity i.e. LoanID. Therefore,
INSTALLMENT is a weak entity.
It is alt is also said that an entity whose instance cannot exist without the
instances of a strong entity is called weak entity. The instances of INSTALLMENT
entity cannot exist without the instances of LOAN entity.
ASSOCIATIVE ENTITY
An associative entity does not exist as other types of entities. It comes into
existence when a many-to-many relationship establishes between the instances of
two related entities.
SIMPLE ATTRIBUTE
An attribute that cannot be subdivided into smaller attributes is called simple
attribute. For example, RollNo of a STUDENT cannot be subdivided. Therefore,
RollNo is a simple attribute.
COMPOSITE ATTRIBUTES
An attribute that can be subdivided into smaller attributes is called
composite attribute. For example, Name of a STUDENT can be subdivided into
FirstName and LastName. Therefore, the Name is a composite attribute.
SINGLE-VALUED ATTRIBUTES
An attribute that can have only one value for an instance is called single
valued attribute. For example, a STUDENT can have only one RollNo. Therefore,
RollNo is a single valued attribute.
MULTI-VALUED ATTRIBUTES
An attribute that may have more than values for an instance is called multi-
valued attribute. For example, a STUDENT may have more than one
TelephoneNo. Therefore, TelephoneNo is a multi-valued attribute.
DERIVED ATTRIBUTES
An attribute that is not actually stored in the database but derived from other
attribute(s) is called derived attribute. For example, Grade of a STUDENT is not
stored in the database. It is derived from Marks. Therefore, Grade is a derived
attribute.
IDENTIFIER
An attribute(s) that can uniquely identify each entity instance within an entity
set is called identifier. For example, RollNo of a STUDENT can uniquely identify an
instance within STUDENT entity set.
3. RELATIONSHIPS
The association between different entity instances is called relationship. For
example, a relationship exists between instances of STUDENT and CLASS because
students are enrolled in the classes.
A relationship is called total if all instances of the entities are related with one
another. A relationship is called partial if some instances of the entities are related with
one another.
DEGREE OF RELATIONSHIPS
The number of entities whose instances are related with one another is
called degree of relationship.
i. UNARY RELATIONHSIP
The relationship of degree one is
called unary relationship. In a unary
relationship, the instances of only one
entity are related with each other.
ii. BINARY RELATIONSHIP
The relationship of degree two is called binary relationship. In a
binary relationship, the instances of two different entities are related with
each other.
iii. TERNARY RELATIONSHIP
The relationship of degree three is called ternary relationship. In a
ternary relationship, the instances of three different entities are related with
each other.
CARDINALITY OF RELATIONSHIPS
The number of entity instances of one entity which are related to the other
entity is called cardinality of relationship.
The most common type of relationship is binary relationship. Therefore, we
will discuss cardinality of the binary relationship.
Depending upon the cardinality, the relationship may be called as one-to-
one relationship, one-to-many relationship, and many-to-many relationship.
i. ONE-TO-ONE RELATIONSHIPS
In one-to-one relationship, one instance of entity X is related to only
one instance of entity Y and one instance of entity Y is also related to only
one instance of entity X.
For example, a company car can be allocated to only one employee
while an employee can be allocated only one company car, then this
relationship is called one-to-one relationship.
MODALITY OF RELATIONSHIPS
The modality of relationships determines whether a relationship is
mandatory or optional. For example, if each company car must be allocated to
some employee then the relationship is mandatory. If each employee may or may
not be allocated a company car then the relationship is optional.
18) EXPLAIN STEP-WISE PROCEDURE OF CREATING AN E-R DIAGRAM WITH THE HELP
OF AN EXAMPLE?
1. One department offers many courses. But one particular course can be offered
by only one department. Hence the cardinality between department and course
is One-to-Many. (1:N)
2. One department has multiple instructors. But instructor belongs to only one
department. Hence the cardinality between department and instructor is One-
to-Many. (1:N)
3. One department has only one head and one head can be the head of only one
department. Hence the cardinality is one to one. (1:1)
4. One course can be enrolled by many students and one student can enroll for
many courses. Hence the cardinality between course and student is Many-to-
Many. (M:N)
5. One course is taught by only one instructor. But one instructor teaches many
courses. Hence the cardinality between course and instructor is Many-to-One.
(N :1)
The process of mapping conceptual schema to data model of the selected DBMS is
called logical database design process. The logical database design describes what is
stored in the database. It describes all entities, attributes and their relationships. It also
describes various constraints on the data. It is the complete description of data stored in the
database.
The logical database design process consists of the following steps:
1. REPRESENT ENTITIES
In this step, each entity in the conceptual model is converted into a relation. The
name of entity becomes name of the relation. The attributes of entity becomes attributes
of the relation. The identifier of entity becomes primary key of the relation.
2. REPRESENT RELATIONSHIPS
In this step, each relationship in conceptual model is also represented in the logical
database design. The representation of a relationship depends upon its type. It may be
represented by including primary key of one of the relation as foreign key in the other
relation or by making a new relation including primary key of both relations as its foreign
keys. The primary key of new relation consists of both foreign keys of the related
relations.
3. NORMALIZE RELATIONS
In this step, the relations created in step 1 and step 2 are normalized. The
normalization helps in controlling unnecessary data redundancy. As a result of the
normalization, new relations are created from the existing relations. The normalization
also helps in removing various database anomalies.
4. MERGE RELATIONS OR DENORMALIZATION
In this steps, the relations resulted from normalization may be merged again. This
process is also called de-normalization. This merging is done to meet performance
constraints of the database.
When a user requests data from multiple relations, it takes more time due to
complexity of the operation. It may be the case that the frequency of such operations is
very high. Therefore, relations are merged to improve the performance of such
operations.
Data Administrator is appointed in very large organizations where more than one
databases are used. Each database is designed, developed and managed by its DBA.
Data Administrator is responsible for overall data of the organization. He develops
organization wide data standards and operating procedures. He also participates with DBAs
in design, development and management of the databases.
RELATION
PROPERTIES OF RELATIONS
23) WHAT ARE KEYS? WRITE A NOTE ON DIFFERENT TYPES OF KEYS IN RELATIONAL
DATABASES?
KEYS
An attribute or set of attributes that have unique values for each tuple is called key.
Therefore, it is used to uniquely identify each tuple in a relation. Keys are defined to enforce
integrity constraints. They are used for searching and sorting the stored data. They are also
used to relate data stored in multiple tables.
1. SUPER KEY
Super key is an attribute or set of attributes that uniquely identifies each tuple in a
relation. It may have some extra attributes. The tuples can also be uniquely identified
without these attributes. A relation may have more than one super key.
2. CANDIDATE KEY
A super key without any extra attribute is called candidate key. It can also be
defined as ‘The minimal super key is called candidate key’. The tuples can also be
identified uniquely with a candidate key. A relation may have more than one candidate
keys.
3. PRIMARY KEY
The selected candidate key is called primary key. A relation may have more than
one candidate keys but only one of them is selected to uniquely identify tuples in a
relation. A relation can have only one primary key.
4. ALTERNATE KEY
A candidate key that is not selected as primary key is called alternate key. It can
also be used to uniquely identify each tuple in a relation. It is used when the value of
primary key is unknown for a tuple. A relation may have more than one alternate key or it
may not have any alternate keys.
5. FOREIGN KEY
An attribute or set of attributes that is used as primary key another table is called
foreign key. The values of foreign key must match to the values of primary key in other
table. It is used to relate data stored in multiple tables. A relation may have more than one
foreign key.
It is important to note that the foreign key does not hold uniqueness property.
6. COMPOSITE KEY
Any key that consists of more than one attributes is called composite key.
ENTITY INTEGRITY
REFERENTIAL INEGRITY
Consider the following LIBRARY SYSTEM with following two relations to clarify the
concepts discussed above:
MEMBER(MemberID, Name, DOB, CNIC#, PhoneNo, Address)
BOOK(BookID, Title, Category, Author, MemberID)
----------------------------------------------------------------------------------------------------------------------------------
The MemberID and CNIC# in MEMBER relation are unique for each tuple.
Similarly BookID in BOOK relation is unique for each tuple also. The BOOK relation also
contains an attribute MemberID which is unique in MEMBER relation but not in the BOOK
relation.
For MEMBER relation
MemberID, PhoneNo √ × × × × √
CNIC#, Address √ × × × × √
MemberID √ √ √ × × ×
CNIC# √ √ × √ × ×
DOB × × × × × ×
-----------------------------------------------------------------------------------------------------------------------
For BOOK relation
BookID, Title √ × × × × √
BookID, Author √ × × × × √
BookID √ √ √ × × ×
MemberID × × × × √ ×
25) WHAT IS NORMALIZATION? WHAT ARE DIFFERENT NORMAL FORMS AND HOW
THEY ARE ACHIEVED?
NORMALIZATION
Normalization is a technique of organizing data in the database. It is a systematic
approach of decomposing tables to eliminate data redundancy and database anomalies. It is
a multi-step process that removes duplicated data from the relations.
PROBLEMS WITHOUT NORMALIZATION
Without normalization, it is very difficult to handle and update data in the database.
Normalization is systematic approach of decomposing tables to eliminate data redundancy
and database anomalies. Anomalies are problems that can occur in a poorly planned and un-
normalized database.
To understand these anomalies consider the following STUDENT relation:
1. UPDATION ANOMALY
Update anomaly occurs when same data item is required to be updated more than
once. It can result into data inconsistency.
In the above relation, if we have to update the ADDRESS of M. Rayyan then we
will have to update it more than once; otherwise the data will be inconsistent. This is
called update anomaly.
2. INSERTION ANOMALY
Insertion anomaly occurs when an additional data needs to be entered when some
data is inserted into the database.
In the above relation, if we have to insert the record of a new student who has not
taken any course yet then we cannot enter his data without entering the information about
course because CourseID cannot be null. This is called insert anomaly.
3. DELETION ANOMALY
Deletion anomaly occurs when some important data is lost while deleting other
data.
In the above relation, if M. Hassaan drops the Physics course then we will have to
delete the entire row. In this way we will lose all the information about M. Hassaan. This
is called delete anomaly.
M304 Calculus B
102 M. Subhan Lahore
C201 Programming Fundamentals C
In the above relation, CourseID, CourseName and Grade are multi-valued attributes.
Therefore, it is not in 1NF. It can be converting into 1NF by eliminating multi-valued
attributes.
The following relation is in 1NF with composite primary key (SID, CourseID):
REGISTRATION
REGISTRATION
In the above relation, SName and Address are partially dependent upon SID
while CourseName is partially dependent upon CourseID. Therefore, it is not in 2NF. It
can be converted into 2NF by splitting it into following three relations:
REGISTRATION
101 C201 A
101 M304 B
102 M304 B
102 C201 C
103 P106 B
STUDENT COURSE
In the above relation, CourseName is dependent upon another non-key attribute i.e.
CourseID. Therefore, it is not in 3NF. It can be converted into 3NF by splitting it into following
two relations:
TEACHER
COURSE
CourseID CourseName
M304 Calculus
The above relations are in 1NF as they do not contain any repeating group.
44 Prof. M. Fahim, Govt. Graduate College, Gulberg, Lahore. 0300 – 774 25 26
PAPER - III DATABASE SYSTEMS
2NF: Identify non-key attributes that are dependent upon part of the key and move them into
a separate table. A relation having simple primary key (a key that consists of only one
attribute) is already in 2NF as the key cannot be sub-divided. Therefore, carefully examine
only those relations which have composite primary key.
CUSTOMER Relation has simple primary key so it is in 2NF.
In ORDER Relation Title and Format are dependent upon part of the key i.e. StockID
so it is not in 2NF. Therefore, we split our relation into following relation:
The above relations are in 2NF as they do not contain any attribute that depends upon part
of the key.
2NF: Identify non-key attributes that are dependent upon other non-key attributes and move
them into a separate table.
ORDER Relation and STOCK Relation do not have any non-key attribute that is
dependent upon a non-key attribute. Therefore, these relations are already in 3NF.
The above relations are in 3NF as they do not contain any non-key attribute that
depends upon another non-key attribute.
CUSTOMER Relation
CustomerID
Name
Address
BranchNo
BRANCH Relation
BranchNo
BranchManager
ORDER Relation
CustomerID
StockID
STOCK Relation
StockID
Title
Format