0% found this document useful (0 votes)
17 views7 pages

DBMS 2022 Summary

1) The document discusses database management and the entity-relationship (E-R) model. 2) Key concepts in the E-R model include entities, attributes, relationships, and relationship types like one-to-one, one-to-many, many-to-one, and many-to-many. 3) The document provides examples of how to create, insert, update, delete and retrieve data from databases using SQL commands.

Uploaded by

Ahmad Umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

DBMS 2022 Summary

1) The document discusses database management and the entity-relationship (E-R) model. 2) Key concepts in the E-R model include entities, attributes, relationships, and relationship types like one-to-one, one-to-many, many-to-one, and many-to-many. 3) The document provides examples of how to create, insert, update, delete and retrieve data from databases using SQL commands.

Uploaded by

Ahmad Umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

DATABASE MANAGEMENT 2022 ENGR.

ABUBAKAR IBRAHIM (07085817280)

PRACTICAL CLASS E-R Relational Model


Visit sqliteonline.com
An entity is an object that exists and is distinguishable from
Tab anywhere and type create table . DatabaseName() other objects. Example: specific person, company, event, plant

 Creating a Table An entity set is a set of entities of the same type that share
the same properties. Example: set of all persons, companies, trees,
Create table student ( holidays

First_name varchar(255),  A relationship : is an association among several entities


Last_name varchar(255), Example:
Id integer(255), Ismail depositor A-102
customer entity relationship set account entity
Gender string(255),
 A relationship set : is a set of relationships of same type
State string(255) // Note at end there is no comma (,)
Types of Relationship Sets
) //closed bracket
On the basis of degree of a relationship set, a relationship set can be
 Inserting Item into Database classified into the following types

INSERT INTO student (First_name, Last_name, Id, Gender, State)  Unary relationship set
 Binary relationship set
VALUES (‘Abubakar’, ‘Ibrahim’, 102, ‘Male’, ’Kano’ );  Ternary relationship set
 N-ary relationship set
 Delete item from Database
 DELETE from student  Unary relationship set is a relationship set where only
 WHERE gender = ’Male’ one entity set participates in a relationship set.
Example : One person is married to only one person
Note : The delete request can contain a nested select that references
the relation from which tuples are to be deleted. example

 DELETE from account


 WHERE balance < (SELECT avg (balance)
FROM account)
 Update Database
 UPDATE student
 SET First_name = Halimatu
 WHERE id = 012
 Binary Relationship set: It is a relationship set involving two
Other Example : entities.
Example: A Relationship involving student and Course.
 SELECT * from Donation_data
 UPDATE Danation_data
 SET first_name = Abdullahi
 WHERE id = 05

 How to Group Data


 SELECT Donor_frequency.count(*)
 FROM Donor.data
 GROUP BY donation_frequency
 Ternary relationship set: is a relationship set where three
Other Example : entities sets participate in a relationship set.

 SELECT NAME, SUM (SALARY)


 FROM Employee
 GROUP BY NAME

NOTE: On sql Sum, average, maximum

 SELECT SUM(Donation) FROM donation_data


 SELECT AVERAGE(Donation) FROM donation_data
 SELECT MAXIMUM(Donation) FROM donation_data

1|Page
DATABASE MANAGEMENT 2022 ENGR. ABUBAKAR IBRAHIM (07085817280)

 N-ary relationship set is a relationship set where ‘n’ entity


 E-R Diagrams
sets participate in a relationship set. Example :

 Mapping Cardinalities
Express the number of entities to which another entity can
be associated via a relationship set.
Most useful in describing binary relationship sets.
For a binary relationship set the mapping cardinality must
be one of the following types:
 One to one
 One to many
 Many to one
 Many to many
 One to one : An entity inA is associated with at most one 1. Entity: An entity may be any object, class, person or place. In
entity in B, and an entity in B is associated with at most one the ER diagram, an entity can be represented as rectangles. Consider
entity in A.
an organization as an example- manager, product, employee,
department etc. can be taken as an entity.

 One to many : An entity in A is associated with any


number (zero or more) of entities in B . An entity in B, a. Weak Entity : An entity that depends on another
however, can be associated with at most one entity in A. entity called a weak entity. The weak entity doesn't
contain any key attribute of its own. The weak entity is
represented by a double rectangle.

2. Attribute
 Many to one : An entity in A is associated with at most
one entity in B. An entity in B, however, can be associated The attribute is used to describe the property of an entity. Eclipse is
with any number (zero or more) of entities in A. used to represent an attribute. For example, id, age, contact number,
name, etc. can be attributes of a student.

A Key : allow us to identify a set of attribute that suffice to distinguish entities


 Many to many : An entity in A is associated with any from each other
number(zero or more) of entities in B, and an entity in B is A super key of an entity set is a set of one or more attributes that taken collectively,
allows us to identify uniquely an entity in the entity sets. Example :
associated with any number (zero or more) of entities in A.
 Customer-id is a super key
 Customer-id + customer-name also a super key
 Customer-name alone is not a super key, because several
people might have the same name

Candidate key : is a minimal super key, suppose that a combination of


customer- and customer-street is sufficient to distinguish among members
of the customer entity set. Then both {customer-id} and {customer-name,
customer-street} are candidate keys customer-id alone is a candidate key

2|Page
DATABASE MANAGEMENT 2022 ENGR. ABUBAKAR IBRAHIM (07085817280)

Generalization Exercises On E-R Diagram


1) Construct an E-R diagram for a car insurance
o Generalization is like a bottom-up approach in which two or company whose customers own one or more cars
more entities of lower level combine to form a higher level each. Each car has associated with it zero to any
number of recorded accidents.
entity if they have some attributes in common.
2) Construct an E-R diagram for a hospital with a set of
o In generalization, an entity of a higher level can also
patients and a set of medical doctors. Associate with
combine with the entities of the lower level to form a further each patient a log of the various tests and
higher level entity. examinations conducted.

o Generalization is more like subclass and superclass system,

but the only difference is the approach. Generalization uses


3) Consider a database used to record the marks that
students get in different exams of different course
the bottom-up approach. offerings. a. Constructan E-R diagram that models
exams as entities, and uses a ternary relationship,
o In generalization, entities are combined to form a more
for the above database.
generalized entity, i.e., subclasses are combined to make a

superclass.For example, Faculty and Student entities can be 4) A University registrar’s office maintains data about
the following entities:
generalized and create a higher level entity Person.
(a) courses, including number, title, credits, syllabus, and
prerequisites;

(b) course offerings, including course number, year, semester,


section number, Instructor(s), timings, and classroom;

(c) students, including student-id, name, and program; and

(d) instructors, including identification number, name,


department, and title.

Specialization Further, the enrollment of students in courses and grades


awarded to students in each course they are enrolled for
o Specialization is a top-down approach, and it is opposite to must be appropriately modeled.

Generalization. In specialization, one higher level entity can Constructan E-R diagram for the registrar’s office. Document
all assumptions that you make about the mapping
be broken down into two lower level entities.
constraints.
o Specialization is used to identify the subset of an entity set
5) Design a Generalization–specialization hierarchy for
that shares some distinguishing characteristics. a motor-vehicle sales company. The company sells
motorcycles, passenger cars, vans, and buses. Justify
o Normally, the superclass is defined first, the subclass and its
your placement of attributes at each level of the
related attributes are defined next, and relationship set are hierarchy. Explain why they should not be placed at
a higher or lower level.
then added.

o For example: In an Employee management system, EMPLOYEE

entity can be specialized as TESTER or DEVELOPER based on

what role they play in the company.

3|Page
DATABASE MANAGEMENT 2022 ENGR. ABUBAKAR IBRAHIM (07085817280)

 NORMALIZATION : Second Normal Form (2NF)


Normalization is a way to organize a data to reduce
redundancy and presents a set of rules that tables o In the 2NF, relational must be in 1NF.
and databases must follow to be well structured.
o In the second normal form, all non-key attributes are fully
 Data Redundancy
functional dependent on the primary key (It should not have
This is the repetition of similar data multiple
times and it results to 3 problems Partial Dependency)
o Deletion Anomaly
o Insertion Anomaly Partial Dependency Occurs when one primary key
o Updating Anomaly determines some other attributes, or if a non-key attribute
depend on a part of a candidate is called Partial Dependency.

First Normal Form (1NF)  If : { (MO-> N )and (M-> P) and (P->N)


 therefore N is dependent partially on MO}
o A relation will be 1NF if it contains an atomic value.
If a non-key attribute depends on the entire candidate, then
o It states that an attribute of a table cannot hold multiple it’s called Fully Dependency
values. It must hold only single-valued attribute.

o 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.

The decomposition of the EMPLOYEE table into 1NF has been


shown below:

Example: Let's assume, a school can store the data of teachers and the
subjects they teach. In a school, a teacher can teach more than one subject.

For a library

1-NF Solution

The given table, non-prime attribute TEACHER_AGE is dependent on TEACHER_ID


which is a proper subset of a candidate key. That's why it violates the rule for 2NF.

To convert the given table into 2NF, we decompose it into two tables:

4|Page
DATABASE MANAGEMENT 2022 ENGR. ABUBAKAR IBRAHIM (07085817280)

The non-prime attributes (EMP_STATE, EMP_CITY) transitively


dependent on super key(EMP_ID). It violates the rule of third normal
form.

That's why we need to move the EMP_CITY and EMP_STATE to the


new <EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.

Third Normal Form (3NF)


o A relation will be in 3NF if it is in 2NF and not contain any

transitive partial dependency.

o 3NF is used to reduce the data duplication. It is also used to ACID Properties in DBMS
achieve the data integrity.
DBMS is the management of data that should remain integrated when
o If there is no transitive dependency for non-prime attributes, any changes are done in it. It is because if the integrity of the data is
affected, whole data will get disturbed and corrupted. Therefore, to
then the relation must be in third normal form. maintain the integrity of the data, there are four properties described in
the database management system, which are known as the ACID
Transitive Dependency : Occurs when one non- properties.
key determines some other attribute, when ever
some indirect relationship happens to cause
functional dependency it is known as Transitive
Dependency.

 If : {A -> B and B -> C are True


 therefore A -> C }

1) Atomicity: The term atomicity defines that the data


remains atomic. It means if any operation is performed on
the data, either it should be performed or executed
completely or should not be executed at all. It further means
that the operation should not break in between or execute
partially. In the case of executing operations on the
transaction, the operation should be completely executed and
not partially. Example

Non-prime attributes: In the given table, all attributes except


EMP_ID are non-prime.

Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and


EMP_ZIP dependent on EMP_ID.

NO ATOMICITY IN THE FIRST DIAGRAM

5|Page
DATABASE MANAGEMENT 2022 ENGR. ABUBAKAR IBRAHIM (07085817280)

4) Durability: Durability ensures the permanency of


something. In DBMS, the term durability ensures that the
data after the successful execution of the operation becomes
permanent in the database.
The durability of the data should be so perfect that
even if the system fails or leads to a crash, the
database still survives. However, if gets lost, it
becomes the responsibility of the recovery
manager for ensuring the durability of the
database.
For committing the values, the COMMIT
ATOMICITY IN THE SECOND DIAGRAM
command must be used every time we make
changes.
2) Consistency: The word consistency means that the
value should remain preserved always.
The integrity of the data should be maintained, which means if a Deadlock in DBMS
change in the database is made, it should remain preserved
always. A deadlock is a condition where two or more transactions are
waiting indefinitely for one another to give up locks. Deadlock
In the case of transactions, the integrity of the data is very
essential so that the database remains consistent before and after is said to be one of the most feared complications in DBMS as
the transaction. The data should always be correct. EXAMPLE no task ever gets finished and is in waiting state forever.
System is deadlocked if there is a set of transactions such that
every transaction in the set is waiting for another transaction in the set.

Deadlock Prevention
 Deadlock prevention protocols ensure that the system will
never enter into a deadlock state. Some prevention
strategies:

 Require that each transaction locks all its data


items before it begins execution (predeclaration).

 Impose partial ordering of all data items and


require that a transaction can lock data items only
3) Isolation: The term 'isolation' means separation. In DBMS, in the order specified by the partial order (graph-
Isolation is the property of a database where no data should affect based protocol).
the other one and may occur concurrently. In short, the operation on
one database should begin when the operation on the first database  wait-die scheme — non-preemptive
gets complete.
It means if two operations are being performed on two  older transaction may wait for younger one to
different databases, they may not affect the value of one release data item. Younger transactions never wait
another. In the case of transactions, when two or more for older ones; they are rolled back instead.
transactions occur simultaneously, the consistency
should remain maintained. Any changes that occur in  a transaction may die several times before
any particular transaction will not be seen by other acquiring needed data item
transactions until the change is not committed in the
memory.  wound-wait scheme — preemptive
Example: If two operations are concurrently running on two different accounts,  older transaction wounds (forces rollback) of
then the value of both accounts should not get affected. The value should remain younger transaction instead of waiting for it.
persistent. As you can see in the below diagram, account A is making T1 and
Younger transactions may wait for older ones.
T2 transactions to account B and C, but both are executing independently
without affecting each other. It is known as Isolation.  may be fewer rollbacks than wait-die scheme.

 Timeout-Based Schemes :

 a transaction waits for a lock only for a specified amount


of time. After that, the wait times out and the transaction
is rolled back.

 thus deadlocks are not possible

 simple to implement; but starvation is possible. Also


difficult to determine good value of the timeout interval.

6|Page
DATABASE MANAGEMENT 2022 ENGR. ABUBAKAR IBRAHIM (07085817280)

References :
Deadlock Detection  https://www.javatpoint.com
Wait for Graph :  Silberschatz−Korth−Sudarshan
Database System Concepts, Fourth
o This is the suitable method for deadlock Edition

detection. In this method, a graph is created Topics :


based on the transaction and their lock. If the  SQL Introduction
created graph has a cycle or closed loop, then  Data modeling (E-R diagram)
there is a deadlock.  Normalization
 Transaction Processing (ACID
o The wait for the graph is maintained by the PROPERTY AND Deadlock)
system for every transaction which is waiting
for some data held by the others. The system
keeps checking the graph if there is any cycle
in the graph
o The system is in a deadlock state if and only
if the wait-for graph has a cycle. Must invoke
a deadlock-detection algorithm periodically
to look for cycles.

7|Page

You might also like