Unit 1
Unit 1
Unit 1
INTRODUCTION TO DBMS
Introduction to Database Management
System
• Database management system consists of two parts:
– Database
– Management System
• Database:
– Data: Facts, figures, statistics etc. having no meaning.
– Record: Collection of related data items.
– Table or Relation: Collection of related records.
– The database is a collection of inter-related data.
Why DBMS ? & What is DBMS ?
What is File System?
• A File Management system is a DBMS that allows
access to single files or tables at a time.
• In a File System, data is directly stored in set of files.
• It contains flat files that have no relation to other files
What is DBMS ?
• A database management system (DBMS) is
system software for creating and managing
databases.
• The DBMS provides users and programmers with
a systematic way to create, retrieve, update and
manage data.
Drawbacks of File Processing System
• Data Abstraction
– Physical level
• Describes how a record (e.g., customer) is
stored.
VIEWS OF DATA - DATA MODELS
– Logical level
• Describes data stored in database, and the
relationships among the data.
– View level
• Application programs hide details of data types.
• Views can also hide information (e.g., salary)
for security purposes.
VIEWS OF DATA - DATA MODELS
Data Models
• Data models define how the logical structure of a
database is modelled.
• It define how data is connected to each other and
how they are processed and stored inside the system.
• The very first data model could be flat data-models,
where all the data used are to be kept in the same
plane.
Data Models
Types of Data Model
– There are basically two types of data model:
• Record based data model
• Object based data model
1) Record based data model
• A fixed number of fields, or attributes in each record type and
each field is usually of a fixed length.
• The three most popular record-based data models are,
Multivalued Attribute
• An attribute can have more than one value.
• The double oval is used to represent multivalued attribute.
Derived Attribute:
• An attribute that can be derived from other attribute is
known as a derived attribute.
• It can be represented by a dashed ellipse.
iii) Relationship
• A relationship is used to describe the relation
between entities.
• Diamond is used to represent the relationship.
Types:
• One-to-One Relationship
• One-to-many relationship
• Many-to-one relationship
• Many-to-many relationship
• One-to-One Relationship
• One-to-many relationship
• Many-to-one relationship
• Many-to-many relationship
Database Languages
• A DBMS has appropriate languages and interfaces to express
database queries and updates.
• Database languages can be used to read, store and update the
data in the database.
• Types of Database Languages
– Data Definition Language (DDL)
– Data Manipulation Language (DML)
– Data Control Language (DCL)
– Transaction Control Language (TCL)
Database System Architecture
Database System Architecture
Database Users:
Users are differentiated by the way they expect
to interact with the system.
• Naive User
• Application Programmers
• Sophisticated Users
• System Analyst
• Database Administrator
Database System Architecture
Naive User:
They don’t have any DBMS knowledge, but they frequently
use the database.
Ex: Railway’s ticket booking users
Application Programmers:
• Also referred as System Analysts or simply Software
Engineers, are the back-end programmers who writes the
code for the application programs
• Application programmers design, debug, test, and maintain
set of programs.
Database System Architecture
Sophisticated Users :
• Sophisticated users can be engineers, scientists,
business analyst, who are familiar with the database.
• They can develop their own database applications
according to their requirement.
System Analyst :
• System Analyst is a user who analyzes the
requirements of parametric end users.
• They check whether all the requirements of end users
are satisfied.
Database System Architecture
Database Administrator
• Schema definition
• Storage structure and access method definition
• Schema and physical organization modification
• Granting user authority to access the database
• Specifying integrity constraints
• Acting as liaison with users
• Monitoring performance and responding to changes in
requirements
Database System Architecture
Query processor:
Translates statements in a query language into low-
level instructions the database manager understands.
• DDL interpreter
• DDL compiler
• Query evaluation engine
Database System Architecture
DDL interpreter
• This will interpret DDL statements and fetch the
definitions in the data dictionary.
DDL compiler:
• This will translate DML statements in a query
language into low level instructions that the
query evaluation engine understands.
Query evaluation engine
• This engine will execute low-level instructions
generated by the DML compiler on DBMS.
Database System Architecture
Storage Manager/Storage Management:
A storage manager is a program module which acts
like interface between the data stored in a database and
the application programs and queries submitted to the
system.
3-Tier Architecture
• The 3-Tier architecture contains another layer
between the client and 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.
Introduction to relational databases
Introduction to relational databases
Relational databases
Data is represented in terms of tuples (rows) in
RDBMS.
What is table/Relation?
• Everything in a relational database is stored in the
form of relations.
• The RDBMS database uses tables to store data.
• A table is a collection of related data entries and
contains rows and columns to store data.
Properties of a Relation:
• Each relation has a unique name by which it is
identified in the database.
• Relation does not contain duplicate tuples.
• The tuples of a relation have no specific order.
• All attributes in a relation are atomic, i.e., each cell
of a relation contains exactly one value.
Database Schema
Database Schema
• A database schema is the skeleton structure that
represents the logical view of the entire database.
• It defines how the data is organized and how the
relations among them are associated.
A database schema can be divided broadly into two
categories
1. Physical Database Schema
2. Logical Database Schema
Database Schema
Database Schema
Physical Database Schema:
• This schema pertains to the actual storage of data and its
form of storage like files, indices, etc.
• It defines how the data will be stored in a secondary
storage
Logical Database Schema:
• This schema defines all the logical constraints that need to
be applied on the data stored.
• It defines tables, views, and integrity constraints.
Keys
Keys
• Keys play an important role in the relational database.
• It is used to uniquely identify any record or row of
data from the table.
• It is also used to establish and identify relationships
between tables.
Types of key:
1. Primary key
2. Candidate key
3. Super Key
4. Foreign key
Keys
Primary key:
• It is the first key which is used to identify one and only one
instance of an entity uniquely.
• An entity can contain multiple keys.
• The key which is most suitable from those lists become a
primary key.
Example:
In the EMPLOYEE table, ID can be primary key since it is
unique for each employee.
In the EMPLOYEE table, we can even select
License_Number and Passport_Number as primary key
since they are also unique.
Keys
Primary key:
Keys
Candidate key
• A candidate key is an attribute or set of an attribute which
can uniquely identify a tuple.
• The remaining attributes except for primary key are
considered as a candidate key.
• Key that consists of two or more
attributes that uniquely identify any record in a
table is called Composite key.
• The candidate keys are as strong as the primary key.
Keys
Candidate keyExample
• 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.
Keys
Super Key
• Super key is a set of an attribute which can uniquely identify
a tuple.
• Super key is a superset of a candidate key.
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.
Keys
Foreign key
• Foreign keys are the column of the table which is used 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.
Keys
Foreign key
Keys
Foreign key
Example
• 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.
Relational Algebra
Relational Algebra
• Select Operation:
• The select operation selects tuples that satisfy a given
predicate.
• It is denoted by sigma (σ).
Syntax:
• σ p(R)
Example:
• σ BRANCH_NAME="perryride" (LOAN)
Relational Algebra
• Project Operation:
• This operation shows the list of those attributes that we wish to
appear in the result.
• Rest of the attributes are eliminated from the table.
• It is denoted by ∏.
Syntax:
• ∏ A1, A2, An (r)
Relational Algebra
Projection - Example
CustomerID CustomerName Status
1 Google Active
2 Amazon Active
3 Apple Inactive
4 Alibaba Active
Syntax:
• R∪S
• Duplicate tuples are eliminated automatically.
Relational Algebra
Union - Example
Table A Table B
column column column column
1 2 1 2
1 1 1 1
1 2 1 3
Table A 𝖴 B
A 𝖴 B gives =>
column 1 column 2
1 1
1 2
1 3
Relational Algebra
• Set Intersection:
• Suppose there are two tuples R and S. The set intersection
operation contains all tuples that are in both R & S.
• It is denoted by intersection ∩.
Syntax:
• R∩S
Relational Algebra
Intersection - Example
Table A Table B
column column column column
1 2 1 2
1 1 1 1
1 2 1 3
Table A ∩ B
A ∩ B =>
column 1 column 2
1 1
Relational Algebra
Cartesian product
• The Cartesian product is used to combine each row in one
table with each row in the other table.
• This type of operation is helpful to merge columns from
two relations.
• It is also known as a cross product.
• It is denoted by X.
Syntax:
EXD
Relational Algebra
Cartesian product
• The Cartesian product is used to combine each row in one
table with each row in the other table.
• This type of operation is helpful to merge columns from
two relations.
• It is also known as a cross product.
• It is denoted by X.
Syntax:
EXD
Relational Algebra
Cartesian Product - Example
Table A Table B
• σ column 2 = '1' (A X B)
• Output – The above example shows all rows from relation A and
σ column 2 = '1' (A X B)
B whose column 2 has value 1 column 1 column 2
1 1
1 1
Relational Algebra
Join Operations
• Join operation is essentially a
Cartesian product followed by a selection criterion.
Inner Join
• In an inner join, only those tuples that satisfy the
matching criteria are included, while the rest are
excluded.
Relational Algebra
Theta Join
• The general case of JOIN operation is called a Theta join.
• It is denoted by symbol θ
Syntax
A ⋈θ B
Example
1 1 1 1 2 3
1 2 1 3
Relational Algebra
EQUI join
1 1 1 1 1 1
1 2 1 3
Relational Algebra
NATURAL JOIN (⋈)
• Natural join can only be performed if there is a
common attribute (column) between the
relations.
• The name and type of the attribute must be same.
C
Num Square
C⋈D
2 4
C⋈D Num Square Cube
3 9
2 4 4
D
3 9 9
Num Cube
2 8
3 18
SQL FUNDAMENTALS
SQL FUNDAMENTALS
Syntax
Create table <table name> ( columnname1 datatype1,
columnname2 datatype2, etc…);
Example
SQL> create table emp
(empno number(4), ename varchar2(30), salary
number(10,2), deptno number(2));
SQL FUNDAMENTALS
Data Definition Language (DDL)
Alter Command
• It is used to add a new column or modify existing column
definitions.
Syntax
Alter table <table name>
Add ( new columnname1 datatype1,
newcolumnname2 datatype2, etc…);