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

Unit-1

Introduction

Veena Parihar
Database Management System

 A Database Management System is a collection of interrelated data and a set


of programs to access those data.
 The primary goal of a DBMS is to provide a way to store and retrieve database
information that is both convenient and efficient.
 Some representative applications of database may be- Banking, Airlines,
Universities, Credit card transactions, Human resources etc.

Veena Parihar
Purpose of Database Systems

 The traditional way of storing data was “File System”.


 To allow users to manipulate the information, the system has a number of
application programs that manipulates the files.
 For a banking system, the programs may be related to
 Debit or credit an account
 Add a new account
 Find the balance of an account
 Generate monthly statements
 New application programs may be added by system programmers if the need
arises.

Veena Parihar
Disadvantages of file systems

 Data Redundancy and Inconsistency


 Difficulty in accessing data
 Data Isolation
 Integrity Problems
 Atomicity Problems
 Concurrent-access anomalies
 Security problems

Veena Parihar
Data Redundancy and Inconsistency

 Since different programmers create the files and application programs over a
long period, the various files are likely to have different structures and the
programs may be written in several programming languages.
 Same information may be duplicated in multiple files.
 Example- address and contact number
 This redundancy leads to higher storage and access cost.
 It may lead to data inconsistancy

Veena Parihar
Difficulty in accessing data

 Conventional file processing environments do not allow needed data to be


retrieved in a convenient and efficient manner.
 Suppose a bank officer needs to find out names of all customers who live
within a particular postal-code area but there is only an application program
that generates list of all the customers.
 The officer must filter out the all customers list or write a new application
program.
 Point is, the requirement may change from time to time and every time you
will need a new application program to access that data

Veena Parihar
Data Isolation

 Because data are scattered in various files, and files may be in different
formats, writing new application programs to retrieve the appropriate data is
difficult.

Veena Parihar
Integrity Problems

 The data values stored in the database must satisfy certain types of
consistency constraints. For example, the balance of certain types of bank
accounts may never fall below a prescribed amount.
 Developers enforce these constraints in the system by adding appropriate
code in the various application programs.
 When new constraints are added, it is difficult to change the programs to
enforce them.

Veena Parihar
Atomicity problems

 Atomic- A transaction must occur completely or not occur at all.


 It is difficult to ensure atomicity in a conventional file-processing system.
 In many applications it is crucial that, if a failure occurs, the data should be
restored to the consistent state existed prior to failure.
 Ex- bank transfers

Veena Parihar
Concurrent access anamolies

 For the sake of overall performance of the system and faster response, many
system allow multiple users to update the data simultaneously.
 In that scenario, interaction of concurrent updates is possible and may result
in inconsistent data.
 To guard against this possibility, the system must maintain some form of
supervision.
 But this supervision is difficult to provide because data may be accessed by
many different application programs that have not been coordinated
previously.

Veena Parihar
Security Problems

 Not every user of the database should be able to access all the data.
 For ex, in a banking system, payroll personnel need to see only that part of
the database that has information about various bank employees. They do not
need access to information about customer accounts.
 Since, application programs are added to the file systems in an ad hoc
manner, enforcing such security constraints is difficult.

Veena Parihar
View of data

 A major purpose of a database system is to provide users with an abstract


view of the data. That is, the system hides certain details of how the data is
stored and maintained.
1. Data Abstraction
2. Instances and Schemas
3. Data Models

Veena Parihar
Data Abstraction

 The need for efficiency has led designers to use complex data structures to
represent data in the database.
 Developers hide the complexity from users through several levels of
abstraction, to simplify users interaction with the system.
 Physical level – the lowest level of abstraction describes how the data are actually
stored. It describes complex low level data structures in detail.
 Logical level – The next higher level of abstraction describes what data are stored
in the database what relationships exist among those data. The logical level
describes the entire database in terms of a small number of relatively simple
structures.
 View level – The highest level of abstraction describes only part of the entire
database. The view level exists to simplify users interaction with the system. The
system may provide many views for the same database.
Veena Parihar
Veena Parihar
1. Physical or Internal Level

 It is the lowest level of abstraction for DBMSs, defining how data is stored, data
structures for storing data, and database access mechanisms. Developers or
database application programmers decide how to store data in the database. It is
complex to understand.
 Example
 The physical level, being the lowest level of abstraction, can be understood with
an example, like how information about a customer is stored in tables while the
data is stored in the form of blocks.
 Another example of physical-level abstraction would be sequential file
organization due to the continuous storage of records. While in indexed file
organizations, we can access the records with the help of indexes.
Veena Parihar
2. Logical or Conceptual Level

 The logical level is the next higher level or intermediate level. It explains what data is
stored in the database and how those data are related. It seeks to explain the complete
or entire data by describing what tables should be constructed and what the linkages
between those tables should be. It is less complex than the physical level.

Example
 The logical level in DBMS is used for representing entities and relationships among
the data stored. For example, defining tables and their attributes and specifying
relationships between them. A table named ‘class’ may have different attributes like
student_name, Roll_no, student ID, and Marks.
 A table named ‘IDs’ contains details about the address of the teacher's ID (foreign
key), and student ID (foreign key).
Veena Parihar
3. View or External Level

 This is the top level. There are various views at the view level, with each view
defining only a portion of the total data. It also facilitates user engagement by
providing a variety of views or numerous views of a single database. All users
have access to the view level. This is the easiest and most simple level.
 Example
 The external level in DBMS defines a part of the entire data and simplifies
interaction with the user by providing multiple views of a similar database. For
example, interacting with a system using a graphical user interface (GUI) to
access an application's features. Here GUI is the view level, and the user does
not know how and what data is exactly stored, i.e hiding the details for the user.

Veena Parihar
Instances and Schemas

• The data which is stored in the database at a particular moment of time is called an
instance of the database.
• The overall design of a database is called schema.
• A database schema is the skeleton structure of the database. It represents the logical
view of the entire database.
• A schema contains schema objects like table, foreign key, primary key, views,
columns, data types, stored procedure, etc.
• A database schema is designed by the database designers to help programmers
whose software will interact with the database. The process of database creation is
called data modeling.

Veena Parihar
Data Models

 A data model is a collection of conceptual tools for describing data, data


relationships, data semantics and consistency constraints. A data model
provides a way to describe the design of a database at the physical, logical
and view level.
 Relational Model
 Entity-Relationship Model
 Object-Based Data Model
 Semi structured Data Model

Veena Parihar
Veena Parihar
Veena Parihar
Data Independance

 Data independence can be explained using the three-schema architecture.


 Data independence refers characteristic of being able to modify the schema
at one level of the database system without altering the schema at the next
higher level.

Veena Parihar
1. Logical Data Independence

 Logical data independence refers characteristic of being able to change the


conceptual schema without having to change the external schema.
 Logical data independence is used to separate the external level from the
conceptual view.
 If we do any changes in the conceptual view of the data, then the user view
of the data would not be affected.
 Logical data independence occurs at the user interface level.

Veena Parihar
2. Physical Data Independence

 Physical data independence can be defined as the capacity to change the


internal schema without having to change the conceptual schema.
 If we do any changes in the storage size of the database system server, then
the Conceptual structure of the database will not be affected.
 Physical data independence is used to separate conceptual levels from the
internal levels.
 Physical data independence occurs at the logical interface level.

Veena Parihar
DBMS Languages

Veena Parihar
1. Data Definition Language (DDL)

 DDL stands for Data Definition Language. It is used to define database


structure or pattern.
 It is used to create schema, tables, indexes, constraints, etc. in the database.
 Using the DDL statements, you can create the skeleton of the database.
 Data definition language is used to store the information of metadata like the
number of tables and schemas, their names, indexes, columns in each table,
constraints, etc.

Veena Parihar
Here are some tasks that come under DDL:

 Create: It is used to create objects in the database.


 Alter: It is used to alter the structure of the database.
 Drop: It is used to delete objects from the database.
 Truncate: It is used to remove all records from a table.
 Rename: It is used to rename an object.
These commands are used to update the database schema that's why they come
under Data definition language.

Veena Parihar
2. Data Manipulation Language (DML)
 DML stands for Data Manipulation Language. It is used for accessing and
manipulating data in a database. It handles user requests.
 Here are some tasks that come under DML:
• Select: It is used to retrieve data from a database.
• Insert: It is used to insert data into a table.
• Update: It is used to update existing data within a table.
• Delete: It is used to delete all records from a table.

Veena Parihar
Data Control Language (DCL)

• DCL stands for Data Control Language. It is used to retrieve the stored or
saved data.
• The DCL execution is transactional. It also has rollback parameters.
 (But in Oracle database, the execution of data control language does not have
the feature of rolling back.)
 Here are some tasks that come under DCL:
• Grant: It is used to give user access privileges to a database.
• Revoke: It is used to take back permissions from the user.

Veena Parihar
4. Transaction Control Language (TCL)

 TCL is used to run the changes made by the DML statement. TCL
can be grouped into a logical transaction.
 Here are some tasks that come under TCL:
• Commit: It is used to save the transaction on the database.
• Rollback: It is used to restore the database to original since the
last Commit.

Veena Parihar
Database Architectures

 1-Tier Architecture
• In this architecture, the database is directly available to the user. It
means the user can directly sit on the DBMS and uses it.
• Any changes done here will directly be done on the database itself. It
doesn't provide a handy tool for end users.
• The 1-Tier architecture is used for development of the local
application, where programmers can directly communicate with the
database for the quick response.

Veena Parihar
2-Tier Architecture

 The 2-Tier architecture is same as basic client-server. In the


two-tier architecture, applications on the client end can
directly communicate with the database at the server side. For
this interaction, API's like: ODBC, JDBC are used.
 The user interfaces and application programs are run on the
client-side.
 The server side is responsible to provide the functionalities like:
query processing and transaction management.
 To communicate with the DBMS, client-side application
establishes a connection with the server side.

Veena Parihar
3-Tier Architecture

• The 3-Tier architecture contains another layer between the client


and server. In this architecture, client can't directly communicate
with the server.
• The application on the client-end interacts with an application
server which further communicates with the database system.
• End user has no idea about the existence of the database beyond
the application server. The database also has no idea about any
other user beyond the application.
• The 3-Tier architecture is used in case of large web application.
Veena Parihar
Veena Parihar
Data Modeling Using the ER Model

 Entity-relationship model is a model used for design and representation of


relationships between data. An Entity–relationship model (ER model)
describes the structure of a database with the help of a diagram, which is
known as Entity Relationship Diagram (ER Diagram).
 An ER model is a design or blueprint of a database that can later be
implemented as a database.

Veena Parihar
Symbols Used in ER Model

• Rectangles: Rectangles represent Entities in ER Model.


• Ellipses: Ellipses represent Attributes in ER Model.
• Diamond: Diamonds represent Relationships among Entities.
• Lines: Lines represent attributes to entities and entity sets with other relationship types.
• Double Ellipse: Double Ellipses represent Multi-Valued Attributes.
• Double Rectangle: Double Rectangle represents a Weak Entity.

Veena Parihar
Veena Parihar
Components of ER Diagram

Veena Parihar
Veena Parihar
Veena Parihar
Veena Parihar
Veena Parihar
Veena Parihar
Veena Parihar
Veena Parihar
Relations

 When an Entity is related to another Entity, they are said to have a


relationship. For example, A Class Entity is related to Student entity,
because students study in classes, hence this is a relationship.
 Depending upon the number of entities involved, a degree is assigned
to relationships.
 For example, if 2 entities are involved, it is said to be Binary
relationship, if 3 entities are involved, it is said to be Ternary
relationship, and so on

Veena Parihar
Veena Parihar
Keys

Veena Parihar
Veena Parihar
Primary key
 It is the first key used to identify one and only one instance of an
entity uniquely. An entity can contain multiple keys, as we saw in
the PERSON table. The key which is most suitable from those lists
becomes a primary key.
 In the EMPLOYEE table, ID can be the primary key since it is
unique for each employee. In the EMPLOYEE table, we can even
select License_Number and Passport_Number as primary keys
since they are also unique.
 For each entity, the primary key selection is based on
requirements and developers.

Veena Parihar
Candidate key

 A candidate key is an attribute or set of attributes that can


uniquely identify a tuple.
 Except for the primary key, the remaining attributes are
considered 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. The rest of the attributes, like SSN,
Passport_Number, License_Number, etc., are considered a
candidate key.

Veena Parihar
Super Key

 Super key is an attribute set that can uniquely identify a


tuple. A super key is a superset of a candidate key.
 For example: In the above EMPLOYEE table,
for(EMPLOEE_ID, EMPLOYEE_NAME), the name of two
employees can be the same, but their EMPLYEE_ID can't be
the same. Hence, this combination can also be a key.
 The super key would be EMPLOYEE-ID (EMPLOYEE_ID,
EMPLOYEE-NAME), etc.

Veena Parihar
Foreign key

 Foreign keys are the column of the table used to point to the primary key of
another table.
 Every employee works in a specific department in a company, and employee
and department are two different entities. So we can't store the department's
information 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.
 In the EMPLOYEE table, Department_Id is the foreign key, and both the tables
are related.

Veena Parihar
Veena Parihar
Alternate key

 the total number of the alternate keys is the total number of


candidate keys minus the primary key. The alternate key may or
may not exist. If there is only one candidate key in a relation, it
does not have an alternate key.
 For example, employee relation has two attributes, Employee_Id
and PAN_No, that act as candidate keys. In this relation,
Employee_Id is chosen as the primary key, so the other candidate
key, PAN_No, acts as the Alternate key.

Veena Parihar
Composite key

 Whenever a primary key consists of more than


one attribute, it is known as a composite key.
This key is also known as Concatenated Key.
 For example, in employee relations, we assume
that an employee may be assigned multiple
roles, and an employee may work on multiple
projects simultaneously.
 So the primary key will be composed of all three
attributes, namely Emp_ID, Emp_role, and
Proj_ID in combination. So these attributes act
as a composite key since the primary key
comprises more than one attribute.

Veena Parihar
Generalization
 Generalization is a bottom-up approach
in which two lower level entities combine
to form a higher level entity. In
generalization, the higher level entity
can also combine with other lower level
entities to make further higher level
entity.
 It's more like Superclass and Subclass
system, but the only difference is the
approach, which is bottom-up. Hence,
entities are combined to form a more
generalised entity, in other words, sub-
classes are combined to form a super-
class.

Veena Parihar
Specialization

 Specialization is opposite to
Generalization. It is a top-down
approach in which one higher
level entity can be broken down
into two lower level entity.
 In specialization, a higher level
entity may not have any lower-
level entity sets, it's possible.

Veena Parihar
Aggregation

 Aggregation is a process when relation


between two entities is treated as a single
entity.
 In the diagram above, the relationship
between Center and Course together, is
acting as an Entity, which is in relationship
with another entity Visitor.
 Now in real world, if a Visitor or a Student
visits a Coaching Center, he/she will never
enquire about the center only or just
about the course, rather he/she will ask
enquire about both.

Veena Parihar
Reduction of ER Diagram to Relationship
Schemas

Veena Parihar
Veena Parihar
Veena Parihar
Solution

Veena Parihar
Veena Parihar
 Applying the rules, minimum 4 tables will be required-
• AR1R2 (a1 , a2 , b1 , c1)
• B (b1 , b2)
• C (c1 , c2)
• R3 (b1 , c1)

Veena Parihar
Veena Parihar
Veena Parihar
Veena Parihar
Veena Parihar
Assignment 1

 1. Consider the relational database of Figure 2.14. What are the appropriate
primary keys.

Veena Parihar
Assignment 1

2. In the instance of
instructor shown in
Figure 2.1, no two
instructors have the
same name. From
this, can we
conclude that name
can be used as a
superkey (or primary
key) of instructor.

Veena Parihar
Assignment 1

3. Consider the bank database of Figure 2.15


a. What are the appropriate primary keys?
b. Given your choice of primary keys, identify appropriate foreign keys.

Veena Parihar
Assignment 1

 4. Explain the distinctions among the


terms primary key, candidate key and
super key.
 5. Consider the following ER diagram
7.22 with redundant relationships. Can
you generate an ER diagram with
removed redundancies. (Hint:
Aggregation)

Veena Parihar
Assignment 1

6. Create an ER diagram for each of the following descriptions:


a. Each company operates four departments, and each department belongs to
one company.
b. Each department in part (a) employs one or more employees, and each
employee works for one department.
c. Each of the employees in part (b) may or may not have one or more
dependents, and each dependent belongs to one employee.
d. Each employee in part (c) may or may not have an employment history.
e. Represent all the ER diagrams described in (a), (b), (c), and (d) as a single ER
diagram.

Veena Parihar
Assignment 1

7. You are required to create a conceptual data model of the data requirements
for a company that specializes in IT training. The Company has 30 instructors and
can handle up to 100 trainees per training session. The Company offers five
advanced technology courses, each of which is taught by a teaching team of two
or more instructors. Each instructor is assigned to a maximum of two teaching
teams or may be assigned to do research. Each trainee undertakes one advanced
technology course per training session.
a. Identify the main entity types for the company.
b. Identify the main relationship types and specify the multiplicity for
each relationship. State any assumptions you make about the data.
c. Using your answers for (a) and (b), draw a single ER diagram to
represent the data requirements for the company.
Veena Parihar

You might also like