0% found this document useful (0 votes)
8 views

unit1_2024

Uploaded by

mrai48851
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)
8 views

unit1_2024

Uploaded by

mrai48851
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/ 83

Unit – 1

Data Base Management System (KCS-501)


Introduction
Database Management System

DBMS is the combination of two words

Database + Management System = DBMS

DBMS is a software designed to assist in maintaining and


utilizing large collection of data

DBMS software can be used to set up the database and


manage the data for updating and retrieval from database
as per our requirements
2
Database Management System
◼ Database :
◼ is a collection of data, typically describing the activities of
one or more related organizations
◼ is a collection of logically related files
◼ a collection of data and information describing items of
interest to an organization

◼ Management System :
Management system is a collection of programs that enables
users to create and maintain the database
3
DBMS Application
◼ Banking : Transactions

◼ Airlines: Reservations and Schedules

◼ Universities: Registration, Result and other information

◼ Sales: Customers, Products and Purchases

◼ Manufacturing: Production, Processing, Inventory etc


◼ .
◼ Human Resources: Employee records, salaries and tax etc.
4
DBMS History
◼ 1950s - 1960s:
◼ Data processing using magnetic tapes for storage and punched cards for

input

◼ 1960s - 1970s:
◼ Hard disks allow direct access to data

◼ Network and Hierarchical data models in general use

◼ Dr. Codd (IBM) introduced the relational data model in 1970

◼ High-performance (for the era) transaction processing

◼ 1980s:
◼ Structure Query Language (SQL)
◼ Parallel and distributed database systems
5
◼ Object-oriented database systems
DBMS History
◼ 1990s:
◼ Large decision support and data-mining applications

◼ Large multi-terabyte data warehouses

◼ Emergence of Web commerce

◼ 2000s +:
◼ XML and XQuery standards

◼ Automated database administration

◼ Increasing use of highly parallel database systems

◼ Data Mining and Data Warehousing

6
DBMS Classification Criteria
◼ Number of supported users
◼ Database site location
◼ Type of database use and Data Model

◼ Single-user DBMS:
◼ On PC – Desktop database

◼ Multi-user DBMS:
◼ Workgroup database (<50 users)

◼ Enterprise database (> 50 users)


7
Drawbacks of using file systems to store data

◼ Data and Application Dependence

◼ Data redundancy and inconsistency


(Multiple file formats & duplication of information in different
files)

◼ Difficulty in accessing data


(Need to write a new program to carry out each new task)

◼ Data isolation — multiple files and format


8
Drawbacks of using file systems to store data (Cont.)

◼ Integrity problems - Integrity constraints

◼ Updates Problem

◼ Concurrent access by multiple users

◼ Security problems

Database system is the solutions regarding the above problems

9
Basic Terminology of Database
◼ Field – A character or group of characters (alphanumeric or numeric)
that has a specific meaning
◼ Record – A set of one or more logically related fields
◼ File – A set of related records

◼ Information- The Combination of data (Raw facts) and knowledge


Data + Knowledge = Information

Input
Application
Data file
program
Output
Frontend Tools Backend Tools 10
Database Schema/Structure and Instances/Record
A database model has two main components:
- Description
- Database itself

The description of database is called the Database Schema


or Database Structure which is specified during database
design and generally it is not change frequently.

A correct schema to the DBMS is extremely important and the


schema must be designed with care.

11
Database Schema and Instances

The data in the database at a particular moment in times is


called a Instances or records. We may insert or delete a
record or change the value of data item in record.

A single entry in a table is called a Tuple or Record or Row. A


tuple in a table represents a set of related data.

The actual data in database may change quite frequently.

12
Database Schema and Instances

Example : Student Table


(s_id: char(4), s_name: char(20), branch : char(5), r_no: integer, remark:char(10))

Database Schema or Database Structure

S_id S_name Branch R_no Remarks


Tuple or Record or Row
1001 Ram IT 3
1002 Shyam CSE 2
1003 Nitin TT 2

Instances or records

13
Practical Example of Database Structure and Records
Write a SQL command to create a table STUDENT with the following specifications field name, data type and size.
Solution :
Filed Name Data Type Size
S_code Integer 5
F_name Varchare 20
L_name Varchare 20
Dept Varchare 10
MySQL> create database college;
MySQL> use college;
MySQL> create table student (
S_code integer(5),
F_name varchar(20),
L_name varchar(20) ,
Dept varchar(10));

Write a SQL commands for alter to add new field DOB in student table and drop the table.

Syntax : alter table table_name add coulumn_name data_type.


MySQL> alter table student add dob date;
MySQL> desc student;
MySQL> alter table student drop column L_name;
MySQL> drop table student; 14
Practical Example of Database Structure and Records
Create the two tables Employee and Department and insert the data as given below:
Solution :

15
Practical Example of Database Structure and Records
Exp. Write SQL commands to:

•Display the names of all the employees working in North zone.


•Display the salaries of all the employees of department 10.
•Display the details of all the employees whose Grade is NULL.
•Display the details of all the employees whose Grade is not NULL.
•Display the names of various zones from the table Employee. A zone name should appear only once.
Solution : (I) & (II) (III) , (IV) and (V)

16
Levels of Abstraction in a DBMS

A Database Management system (DBMS) provides three


levels of abstraction of Three-Schema Architecture.

- External Schema (User View)

- Conceptual Schema (Table Structure Design)

- Physical Schema (Physical Database)

17
Levels of Abstraction in a DBMS
External Schema 1 External Schema 2 External Schema 3

Conceptual Database structure/


(logical) Schema
Schema

Physical Database
Schema

Secondary HDD/CD ROM/etc.


Storage 18
Physical Schema
◼ The physical schema specifies storage details.

◼ The physical schema summarizes how the relation described


in the conceptual schema are actually stored on secondary
storage device such as disks and tapes.

◼ The physical schema is also responsible for storing all


relations as unsorted files and creating an index to speed up
data retrieval operation.

19
Conceptual (Logical) Schema
◼ The conceptual schema describes the stored data in terms of
the data model of the DBMS.

◼ In a relation DBMS, the conceptual schema describes all


relation that are stored in the database.

◼ It describes all records and relationships included in the


conceptual view and therefore, in the database,.

20
Conceptual (Logical) Schema
Example: Book table
(bid: char(2), title: char(50), author: char(20), price:
decimal(5,2), av_q: integer)

Example :Customer table


(cid: char(2), l_n: char(25), f_n: char(25), a_c: char(30),
phone: char(10))

21
External Schema
◼ The external schema consists of the definition of the
logical records and the relationships in the external view

◼ Each external schema contains of a collection of one or


more views and relations from the conceptual schema

◼ A view is conceptually a relation, but records in view are


not stored in the DBMS.

◼ Reduce complexity of DBMS for users

◼ Support data security 22


Data Independence
◼ Data Independence is achieved through use of the three
levels of data abstraction

◼ Data Independence can be define as the capacity to


change the schema at one level of a database system
without having to change the schema at the next higher
level

◼ We can define two type of data independence


◼ Logical Data Independence
◼ Physical Data Independence

23
Data Independence
External Schema 1 External Schema 2 External Schema 3

Logical data Independence


Conceptual
Schema

Physical data Physical Independence


Schema

Secondary
Storage 24
Logical Data Independence
◼ Logical data independence is the capacity to change
the conceptual schema with out having to change
external schemas or application programs

◼ EX. We may change conceptual schema to expand the


database by adding a records or reduce the database by
removing a record

◼ Ex. Logical data independence also provides to change


the constraints in conceptual schema without affecting
external schemas or application programs
25
Physical Data Independence
◼ Physical data independence is the capacity to
change the physical schema without having to
change the conceptual or external schemas.

◼ Change in physical storage of the data

26
Database Architecture
Database Architecture uses programming languages to design
a particular type of software for businesses or organizations.

Database Architecture focuses on the design, development,


implementation and maintenance of computer programs that store
and organize information for businesses, agencies and institutions.

To understand the structure of DBMS, they are classified into


three types based on their build architecture:

•One-Tier Architecture.
•Two-Tier Architecture.
•Three-Tier Architecture.
27
Database Architecture

28
DBMS Components
◼ Data Model

◼ Data Dictionary (System Catalog)


◼ Meta data

◼ Database languages
◼ Data Definition language (DML)
◼ Data Manipulation language (DDL)
29
Data Model
◼ Data Model gives us an idea that how the final system will
look like after its complete implementation. It defines the
data elements and the relationships between the data
elements. Data Models are used to show how data is
stored, connected, accessed and updated in the
database management system.

◼ There are three types of data models:


◼ Hierarchical Model,

◼ Network Model,

◼ Relational Model.

◼ These models have further categories which are used


according to a different use case. 30
Hierarchical Database Model
◼ The hierarchal model based on two data structuring concepts:
◼ Records
◼ Parent-Child relationship

◼ IBM developed the Management Information System (MIS) For


Hierarchical Database Model.

◼ A parent-child relationship is a 1:N relationship between two


record types

31
Hierarchical Database Model

32
Network Database Model
◼ In network model terminology, a relationship is called a set.

◼ Each set is composed of at least two records.

◼ The difference between the hierarchical and the network


model is that the network model might include a condition
in which a member can appear as member in more than
one set.

◼ In other words, a member may have several owners.

◼ A set represents a M:M relationship between the owner and


the member 33
Network Model

34
Relational Data Model
◼ Before 1970 most the database system were based on two
models i.e. Hierarchical Model or Network Model

◼ Dr. Codd (IBM Scientist) proposed a relational Data Model in


1970. and SQL is standard data management language for
relational DBMSs.

◼ A RDBMS is a Database Management system which is based


on relational model as introduced by Dr. Codd.

◼ Today, popular RDBMS are Microsoft Access, MSSQL,MYSQL,


Oracle,Sybase,DB2 and Informix. 35
Relational Data Model

36
Relational Algebra
◼ Relational Algebra is a procedural query language. It consists of
set of operations that take one or two relations as input and
produce a new relation as their result.
◼ Relational Algebra is of following eight types:
1. Select (σ )
2. Project (Π )
3. Product (X)
4. Unions (U)
5. Differences (- )
6. Intersection ( )
7. Join ( )
8. Divide/ Division ( / )
Data Model

38
Data Dictionary
A Data Dictionary is a collection of names, definitions,
and attributes about data elements that are being
used or captured in a database, information system, or
part of a project.

A Data Dictionary also provides metadata about data


elements.

39
Database Language
◼ A language is needed to describe the database to the DBMS
as well provide facilities for changing the database and
physical data structure.

◼ The two languages are the part of database language


◼ Extended Host Language – These are subroutine calls from
one or more programming languages and used to interact
with database (Ex. Visual Basic, Dot Net etc.)

◼ Query Language – These are special purpose language


that usually provide more powerful to interact with
database and non programmers may be easily use. These
are categorized in two type:
◼ Data Definition Language (DDL)
40
◼ Data Manipulation Language (DML)
Data Definition Language (DDL)
Data Definition Language (DDL) can be used to define the
conceptual schemas and also give some details about how to
implement this schema in physical devices used to store data.

DDL is used by the DBA by database designer to define both


schemas

The basic function of DDL include following:

◼ Creation of data structure supported by data modal (CREATE TABLE)


◼ Modification of data structure (ALTER TABLE)
◼ Deletion of data structure (DROP TABLE)
◼ Creation of indexes on particular data items for data access (CREATE
INDEX) 41
Data Manipulation Language (DML)
Data Manipulation Language (DML) that enables users to
access or manipulate as organized by the appropriate data
model

DML provides commands to select and retrieve data from the


database designer to define both schemas

The basic function of DML include following:


◼ Retrieval data (SELECT operator for relational model)
◼ Modification of data (UPDATE operator)

◼ Deletion of data (DELETE operator)

◼ Creation of new data (INSERT operator)

◼ Most DML have built in function (SUM, COUNT and AVG etc.)
42
Difference between DBMS and RDBMS

43
Database Administrators (DBA)
◼ Database administrators (DBAs) use specialized Data
base software to store and organize the data.

◼ The role of DBAs are :

◼ Capacity planning,
◼ Installation and Configuration,
◼ Database Design,
◼ Performance Monitoring,
◼ Security and troubleshooting,
◼ Authentication or Privilege
44
◼ Backup and Data Recovery.
Structure of DBMS
Query evaluation Engine

Concurrency File and Access Methods


Control

Transaction Buffer Manager Recovery


Manager Manager
Lock
Manager Disk space Manager

Database
Index Files
Data Dictionary
Data Files
45
Entity Relationship Model (ER Model )
◼ 1976 proposed by Peter Chen

◼ ER diagram is widely used in database design

◼ Represent conceptual level of a database system

◼ ER model consists of a collection of basic object,


called entities and relation among these object

46
Basic Concepts
◼ Entity - The entity is a thing or object in the world that has some independent existence with
some properties that make it differs from other. In other words entity is something that has on
identity

◼ Entity set – An Entity set is a set of entities of the same type that share the same properties
or attributes. An entity set contains many entities Ex. CAR (MAURTI , TATA, etc. )

◼ Weak Entity Set- An entity set which does not have a primary key

◼ Strong Entity Set- An entity set which have a primary key

◼ Attributes - common properties of the entities in a entity sets


Ex. Car no., Car Color, Car Year, Car Model etc.

◼ Relationship – specify the relations among entities from two or more entity sets

◼ Domain - The Domain of an attributes is the collection of all possible values, an attribute
47can
Notations of ER Diagram

48
Notations of ER Diagram

49
Example : ER Model

50
Example : ER Diagram with Weak & Storing Entity Set

51
Relationship
◼ A relationship may be thought as a set as well
◼ For binary relationship, it enumerates the pairs of
entities that relate to each other

◼ For example, entity set M = {Mike, Jack, Tom}


entity set F = {Mary, Kate}. The relationship set
married between M and F may be
{<Mike,Mary>,<Tom, Kate>}

52
Relationship Example

53
Attribute of A Relationship Set

54
Relationship
• The degree of a relationship = the number of
entity sets that participate in the relationship
– Mostly binary relationships
– Sometimes more
• Mapping cardinality of a relationship
– 1 –1
– 1 – many
– many – 1
– Many-many

55
One-One and One-Many

56
Many-one and many-many

57
1- many

One customer and many loan facilities

58
Many - 1

Many customers and one loan facility

59
Many - many

Many customers and many loan facilities

Ex. ER Diagram corresponding to customer and loan

60
Total Participation
When we require all entities to participate in the relationship
(total participation), we use double lines to specify

Every loan has to have at least one customer

61
Self Relationship
◼ Sometimes entities in a entity set may relate to other
entities in the same set. Thus self relationship
◼ Here employees mange some other employees
◼ The labels “manger” and “worker” are called roles the
self relationship

62
More examples on self-relationship
◼ People to people
◼ Parent – Children
◼ Manager – Employee
◼ Husband – Wife

◼ Word to word
◼ Root – Synonym

63
Type of Attributes
◼ Single Value Attributes (Single Ellipse)
Ex. Student Roll No.

◼ Multi-Valued Attributes (Double Ellipse)


Ex. Phone No.

◼ Derive Attributes (Dashed Ellipse)


Ex. Age derived from Date of Birth

◼ Composite Attributes (Single Ellipse)


Ex. Name (First Name, Middle Name & Last Name) 64
Ex. ER Diagram with Composite, Multi-valued and Derived Attributes

65
Ex. ER Diagram for Entity with Attribute

66
Ex. ER Diagram for Student and Faculty

67
Ex. ER Diagram for Customer, order and Product

68
Keys
A Key is a value which can always used to unique identification
an object instance
Student Table
Roll No Name Branch Semester Remarks
1001 Ram IT 3
1002 Shyam CSE 2
1003 Nitin TT 2
A Super key is a set of one or more attributes that taken collectively
allow us to identify uniquely an entity in the entity set.
Ex. Supper Key, S=(Roll No, Name, Branch)
S=(Name , Branch, Semester)
A Candidate key can be defined as the minimum number of super key
that identifies the record uniquely. 69
Keys
◼ A Primary key can be defined as the minimum number
of candidate key that is chosen by the database designer
as the principal means of identifying entities within an
entity set. There should not be any duplicate in the record
of primary key.
Ex. Primary Key, P=(Roll No)

◼ A Foreign key is a column whose values are the same as


the primary key of another table. The relationship is made
between two relational table by matching the value of the
foreign key in one table with the values of the primary
key in another 70
Key Examples
◼ Suggest super keys for the following entity?
◼ What are the candidate keys?
◼ Primary key?

Author

name death

birthday description

71
Extended ER Model
◼ The Extended Entity Relationship Model (EER) model
include all the modeling concepts of the ER model and
the concepts of specialization , generalization, higher-
level and lower-level entity set attributes inheritance and
aggregation.

72
Generalization
◼ Generalization is a relationship that exists between a high-
level entity set and lower-level entity set.

◼ Generalization is represent by triangle component labeled


ISA.

◼ The label ISA stands for “is a”

ISA

73
Example of Generalization
◼ A person is a high-level entity set and customer
and employee are lower-level entity set .

◼ The person entity set is the superclass and


customer & Employee are subclass.

◼ The ISA relationship may be referred as a


superclass-subclass relationship

74
Fig. Generalizing Car and Truck Entities

75
Specialization Inheritance and Attribute Inheritance
◼ The process of designing sub groupings with an entity set is called
specialization.

◼ A lower-level entity set inherits all the attributes and relationship


participation of the higher-level entity set to which it is linked.

◼ A lower-level entity set may have additional attributes and


participate in additional relationships

◼ Attribute Inheritance: A Crucial property of the higher and lower


level entities created by specialization and generalization is attribute
inheritance. The attributes of the higher level entity sets are said to
be inherited by the lower level entity sets.
(Ex. Customer and Employee inherit the attributes of person) 76
Fig. ER diagram with Generalization and Specialization

Generalization

Specialization

77
Aggregation
◼ Aggregation is a technique to express relationship
among relationship.

◼ Through E-R modeling we cannot express


relationship among relationships. Thus we use the
concept of aggregation for this purpose.

◼ Aggregation is an abstraction through which


relationships are treated as entities
78
Fig. ER diagram with Aggregation

79
Relationship Degree

• The degree of a relationship type is the number of participating


entities in relation.

• A relationship type of degree two is called binary relationship.

• A relationship type of degree three is called ternary


relationship.

• If there is a relationship that involves N entities called N-array


relationship.

80
Fig. Binary and Ternary Relationship

81
Ex. Reduction of ER diagram to Table

82
Ex. Reduction of ER diagram to Table

83

You might also like