Database Analysis-Unit-1I: Course Name: Faculty Name

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

Database Analysis-Unit-1I

Course Name: Faculty Name:


Database Zaiba Khan
Management
System Assistant
Branch- Professor(CSE)
School of
B.Tech V Semester
Engineering &
Course Code: Technology
19007800
Mapping Constraints

A mapping constraint is a data constraint that


expresses the number of entities to which another
entity can be related via a relationship set.

Itis most useful in describing the relationship sets


that involve more than two entity sets.

For binary relationship set R on an entity set A and


B, there are four possible mapping cardinalities.
These are as follows:
◦ One to one (1:1)
◦ One to many (1:M)
◦ Many to one (M:1)
◦ Many to many (M:M)
One to One

 In one-to-one mapping, an entity in E1 is associated


with at most one entity in E2, and an entity in E2 is
associated with at most one entity in E1
One to Many

 In one-to-many mapping, an entity in E1 is associated


with any number of entities in E2, and an entity in E2
is associated with at most one entity in E1
Many to One

 In one-to-many mapping, an entity in E1 is associated


with at most one entity in E2, and an entity in E2 is
associated with any number of entities in E1
Many to Many

 In many-to-many mapping, an entity in E1 is


associated with any number of entities in E2, and an
entity in E2 is associated with any number of entities
in E1
What is RDBMS?

 RDBMS stands for Relational Database


Management Systems

 All modern database management systems


like SQL, MS SQL Server, IBM DB2, ORACLE,
My-SQL and Microsoft Access are based on
RDBMS

 Itis called Relational Data Base Management


System (RDBMS) because it is based on
relational model introduced by E.F. Codd
Relational Model Concept

Relational model can represent as a table with


columns and rows. Each row is known as a
tuple. Each table of the column has a name or
attribute.

 Domain: It contains a set of atomic values


that an attribute can take.

 Attribute: It contains the name of a column


in a particular table. Each attribute Ai must
have a domain, dom(Ai)
Relational Model Concept

 Relationalinstance: In the relational


database system, the relational instance is
represented by a finite set of tuples. Relation
instances do not have duplicate tuples

 Relationalschema: A relational schema


contains the name of the relation and name of
all columns or attributes

 Relational key: In the relational key, each


row has one or more attributes. It can identify
the row in the relation uniquely
Relational Model Concept(Example)
Properties of Relations

 Name of the relation is distinct from all other relations.

 Each relation cell contains exactly one atomic (single)


value

 Each attribute contains a distinct name

 Attribute domain has no significance

 Tuple has no duplicate value

 Order of tuple can have a different sequence


Super key in DBMS

 Definition of Super Key in DBMS: A super


key is a set of one or more attributes
(columns), which can uniquely identify a row
in a table. Often DBMS beginners get
confused between super key and
candidate key, so we will also discuss
candidate key and its relation with super key
in this article.
Super key in DBMS

How candidate key is different from super


key?
 Answer is simple – Candidate keys are
selected from the set of super keys, the only
thing we take care while selecting candidate
key is: It should not have any redundant
attribute. That’s the reason they are also
termed as minimal super key.
Super key in DBMS-Example

Super keys: The above table has following super keys. All
of the following sets of super key are able to uniquely
identify a row of the employee table.
Super key in DBMS-Example

 {Emp_SSN}
 {Emp_Number}
 {Emp_SSN, Emp_Number}
 {Emp_SSN, Emp_Name}
 {Emp_SSN, Emp_Number, Emp_Name}
 {Emp_Number, Emp_Name}
Super key in DBMS-Example

Candidate Keys: A candidate key is a minimal


super key with no redundant attributes. The
following two set of super keys are chosen from
the above sets as there are no redundant
attributes in these sets.

 {Emp_SSN}
 {Emp_Number}
 Onlythese two sets are candidate keys as all
other sets are having redundant attributes that
are not necessary for unique identification.
1. First you have to understand that all the candidate keys
Super Key vs. Candidate Key

are super keys. This is because the candidate keys are


chosen out of the super keys.
2. How we choose candidate keys from the set of super
keys? We look for those keys from which we cannot
remove any fields. In the above example, we have not
chosen {Emp_SSN, Emp_Name} as candidate key
because {Emp_SSN} alone can identify a unique row in
the table and Emp_Name is redundant.
 Primary key:
A Primary key is selected from a set of candidate keys.
This is done by database admin or database designer. We
can say that either {Emp_SSN} or {Emp_Number} can be
chosen as a primary key for the table Employee.
A candidate key is an attribute or set of an attribute
Candidate Key


which can uniquely identify a tuple.

 The remaining attributes except for primary key are


considered as a candidate key. The candidate keys are
as strong as the primary key.

 For example: In the EMPLOYEE table, id is best suited


for the primary key. Rest of the attributes like SSN,
Passport_Number, and License_Number, etc. are
considered as a candidate key.
Candidate Key
Foreign Key
Foreign keys are the column of the table which is used
Foreign Key


to point to the primary key of another table
 In a company, every employee works in a specific
department, and employee and department are two
different entities. So we can't store the information of
the department in the employee table. That's why we
link these two tables through the primary key of one
table.
 We add the primary key of the DEPARTMENT table,
Department_Id as a new attribute in the EMPLOYEE
table.
 Now in the EMPLOYEE table, Department_Id is the
foreign key, and both the tables are related.
Normalization is a process of organizing the data in
Normalization


database to avoid data redundancy, insertion anomaly,
update anomaly & deletion anomaly. Let’s discuss
about anomalies first then we will discuss normal
forms with examples.

Anomalies in DBMS
 There are three types of anomalies that occur when the
database is not normalized. These are – Insertion,
update and deletion anomaly. Let’s take an example to
understand this.
Example: Suppose a manufacturing company stores the
employee details in a table named employee that has
Normalization-Example

four attributes: emp_id for storing employee’s id,


emp_name for storing employee’s name, emp_address
for storing employee’s address and emp_dept for
storing the department details in which the employee
works. At some point of time the table looks like this:
 Update anomaly: In the above table we have two rows for
employee Rick as he belongs to two departments of the
Normalization-Example

company. If we want to update the address of Rick then we


have to update the same in two rows or the data will become
inconsistent. If somehow, the correct address gets updated in
one department but not in other then as per the database,
Rick would be having two different addresses, which is not
correct and would lead to inconsistent data.
 Insert anomaly: Suppose a new employee joins the company,
who is under training and currently not assigned to any
department then we would not be able to insert the data into
the table if emp_dept field doesn’t allow nulls.
 Delete anomaly: Suppose, if at a point of time the company
closes the department D890 then deleting the rows that are
having emp_dept as D890 would also delete the information of
employee Maggie since she is assigned only to this
department.
To overcome these anomalies we need to normalize the data.
Types of Normalization
Normal Form Description
1NF A relation is in 1NF if it contains an atomic
Types of Normalization

value.
2NF A relation will be in 2NF if it is in 1NF and all
non-key attributes are fully functional
dependent on the primary key.
3NF A relation will be in 3NF if it is in 2NF and no
transition dependency exists.
4NF A relation will be in 4NF if it is in Boyce Codd
normal form and has no multi-valued
dependency
5NF A relation is in 5NF if it is in 4NF and not
contains any join dependency and joining
should be lossless
 A relation will be 1NF if it contains an atomic value.
 It states that an attribute of a table cannot hold multiple
Types of Normalization(1NF)

values. It must hold only single-valued attribute.


 First normal form disallows the multi-valued attribute,
composite attribute, and their combinations.
 Example: Relation EMPLOYEE is not in 1NF because of
multi-valued attribute EMP_PHONE.
Types of Normalization(1NF)

 The decomposition of the EMPLOYEE table into 1NF has been


shown below:

You might also like