Bilal Dbms Unit-1
Bilal Dbms Unit-1
DB
MANAGEMENT
UNIT-I M
Presented By
S Mohammad Bilal J
SYSTEM Assistant professor
Department I.T
VCE
Course Outcomes
✓ C01- Demonstrate design and implementation of a database for a given problem domain.
✓ CO4- Analyze various transaction control and recovery methods to keep data base consistent.
✓ C05- Construct the file of data records by using appropriate storage and access structure.
Text Books
1. Raghurama Krishnan, Johannes Gehrke., Database Management Systems, 3rd Edition,Tata McGraw-
Hill, New Delhi, India, 2014.
2. Abraham Silberschatz, Henry F. Korth, S. Sudarshan., Database System Concepts,7th Edition, McGraw-
Hill, New Delhi, India, 2019.
UNIT-1
✓ It takes variety of forms, including numeric data, text and voice and images.
ii. Information:
✓ Data that have been processed in such a way as to increase the knowledge of the person who uses
the data.
✓ It is also used to organize the data in the form of a table, schema, views, and reports, etc.
✓ Example: The college Database organizes the data about the admin, staff, students and faculty etc.
✓ By using the database, the information can be easily retrieved, inserted, and deleted.
✓ The goal of DBMS is to provide a way to store and retrieve information in a convenient and efficient
manner.
Introduction to Database Management System
Functions of a DBMS:
i. Concurrency : concurrent access (meaning 'at the same time') to the same database by
multiple users.
iii. Backup and recovery : processes to back-up the data regularly and recover data if a problem
occurs.
iv. Integrity : database structure and rules improve the integrity of the data.
Advantages of DBMS
✓ Reduced updating errors.
✓ Example of such systems are File Handling in High Level Languages like C, Basic and COBOL etc.,
✓ Management of data involves both defining structures for storage of information and providing
mechanisms for the manipulation of information.
✓ Database system must ensure the safety of the information stored, when the system crashes or
attempts at unauthorized access.
Database System Applications
✓ The Databases are used in many areas and many applications. Some of the Database Applications.
1. Banking :For customer information, accounts, and loans, and banking transactions.
2. Airlines :For reservations and schedule information. Airlines were among the first to use
4. Credit card transactions :For purchases on credit cards and generation of monthly statements.
5. Telecommunication :For keeping records of calls made, generating monthly bills, maintaining balances on
prepaid calling cards, and storing information about the communication networks.
Database System Applications
6. Finance :For storing information about holdings, sales, and purchases of financial
9. Human resources :For information about employees, salaries, payroll taxes and benefits.
3. Integrity Problems:
✓ Hard to add new constraints or change existing ones
Drawbacks of File System
4. Atomicity Problems:
✓ Failures may leave database in an inconsistent state with partial updates carried out.
Example:
Transfer of funds from one account to another should either complete or not happen at all.
6. Security Problems:
✓ Not every user of the database system should be able to access all the data.
Database System Vs File System
File Management System Database Management System
✓It is easy-to-use system to store general files which ✓It is used when security constraints are high.
require less security and constraints.
✓Complex to maintain non-redundant data. ✓Due to normalization easy to maintain non-redundant data.
✓User locates the physical address of the files to ✓User is unaware of physical address where data is stored.
access data .
✓ To fully understand the view of data, you must have a basic knowledge of 2
components
Physical Level
i. Data Abstraction
✓ To ease the user interaction with database, the developers hide internal irrelevant details from users.
✓ This process of hiding irrelevant details from user is called data abstraction.
✓ The term “irrelevant” used here with respect to the user, it doesn’t mean that the hidden data is not relevant with
regard to the whole database.
✓ It just means that the user is not concerned about that data.
view of data
✓ There are three levels of abstractions
✓ You can get the complete data structure details at this level.
✓ You are just concerned about the message that pops up when your ticket is successfully booked.
✓ This doesn’t mean that the process happening at the back end is not relevant, it just means that you as a user
are not concerned what is happening in the database.
view of data
Example-2:
✓Let’s say we are storing customer information in a customer table:
✓At physical level these records can be described as blocks of storage (bytes, gigabytes, terabytes etc.) in memory.
These details are often hidden from the programmers.
✓At the logical level these records can be described as fields and attributes along with their data types, their
relationship among each other can be logically implemented. The programmers generally work at this level because
they are aware of such things about database systems.
✓At view level, user just interact with system with the help of GUI and enter the details at the screen, they are not
aware of how the data is stored and what data is stored; such details are hidden from them.
view of data
ii. Instance and schema:
✓ Design of a database is called the schema.
Example:
✓ Schema helps the database users to understand the relationship between data.
a) Physical schema
b) logical schema
c) view schema
view of data
view of data
i. Physical Schema :
✓The design of a database at physical level is called physical schema.
✓ It describes the physical storage structure of the database.
✓How the data stored in blocks of storage is described at this level.
ii. Logical schema :
✓Design of database at logical level is called logical schema
✓Programmers and database administrators work at this level
✓ what type of data records gets stored in data structures.
iii. View schema :
✓Design of database at view level is called view schema.
✓This generally describes end user interaction with database systems.
✓This schema allows data access to be customized at the level of individual users or groups of users.
view of data
Definition of instance:
✓The data stored in database at a particular moment of time is called instance of database.
Example:
✓ we have seen the schema of table “employee”.
✓ Let’s see the table with the data now.
✓At this moment the table contains two rows (records). This is the current instance of the table “employee”
because this is the data that is stored in this table at this particular moment of time.
Database Users and Administrators
DATABASE USERS:
✓Database users are the persons who interact with the database and take the benefits of database.
✓Different types of users are:
i. Naive users
ii. Application programmers
iii. Stand-alone users
iv. Sophisticated users
v. Specialized users
vi. System Analyst
Database Users and Administrators
i. Naive users:
✓Naive users or Parametric End Users are the unsophisticated who don’t have any DBMS knowledge but they
frequently use the data base applications in their daily life to get the desired results.
Example:
ATMs (Automated Teller Machine), Railway’s ticket booking users, Clerks in any bank etc.
1. Query Processor:
✓The query processor helps the database system simplify and facilitate access to data.
✓It interprets the requests (queries) received from end user via an application program into instructions.
✓The query processor components include:
i. DDL interpreter
ii. DML compiler
iii. Query evaluation engine
Database System Structure
i. DDL interpreter:
✓It processes the DDL statements into a set of table containing meta data .
ii. DML compiler:
✓It translates DML statements in a query language into low-level instructions that the query evaluation engine
understands, so that they can be executed.
✓A query can usually be translated into any of a number of alternative evaluation plans that all give the same
result.
✓The DML compiler also performs query optimization, that is, it picks the lowest cost evaluation plan from among
the alternatives.
iii. Query evaluation engine:
✓ It executes low-level instructions generated by the DML compiler.
Database System Structure
2. Storage Manager:
✓It is also known as Database Control System.
✓It is responsible for updating, storing, deleting, and retrieving data in the database.
✓It translates the various DML statements into low-level file-system commands.
✓ It maintains the consistency and integrity of the database by applying the constraints and executing the DCL
statements.
✓The Storage Manager components include:
i. Buffer manager
ii. File manager
iii. Authorization and Integrity Manager
iv. Transaction manager
Database System Structure
i. Buffer Manager:
✓ It is responsible for fetching data from disk storage into main memory, and deciding what data to cache in main
memory.
ii. File Manager:
✓It manages the file space and the data structure used to represent information in the database.
iii. Authorization and Integrity Manager:
✓ It ensures role-based access control, i.e,. checks whether the particular person is privileged to perform the
requested operation or not.
✓It checks the integrity constraints when the database is modified.
iv. Transaction Manager:
✓A transaction is a collection of operations that performs a single logical function in a database application.
✓It ensures that the database remains in the consistent state before and after the execution of a transaction.
✓It controls concurrent access by performing the operations in a scheduled way that it receives the transaction.
Database System Structure
3.Disk Storage:
✓It contains three components:
i. Data Files
ii. Data Dictionary
iii. Indices
i. Data Files:
✓ It stores the data.
ii. Data Dictionary:
✓ It contains the information about the structure of any database.
✓ It is the repository of information that governs the metadata.
iii. Indices:
✓ It provides faster retrieval of data item.
Database design
The design process consists of the following steps:
✓Gather all of the types of information you might want to record in the database.
✓Divide your information items into major entities or subjects . Each subject then becomes a table.
✓Decide what information you want to store in each table. Each item becomes a field, and is displayed as a column
in the table.
Database design
✓Choose each table’s primary key. The primary key is a column that is used to uniquely identify each row.
the results you want from your tables. Make adjustments to the design, as needed.
✓It specifies the data items as well as the relationships between them.
✓These are often used to show how data is connected, stored, accessed, and changed.
1. Hierarchical Model
2. Network Model
3. Entity-Relationship Model
4. Relational Model
✓ This is one of the oldest models in a data model which was developed by IBM, in the 1950s.
✓ The Hierarchical Model was the first database management system model.
✓ The hierarchy begins at the root, which contains root data, and then grows into a tree as child nodes are
✓ In this model, a child node will only have a single parent node.
✓ This model efficiently describes many real-world relationships like index of a book, food recipes, website
✓An entity-type can be a real-world object either living or non-living like a person, place, concept, object, or
event.
Example:
✓In a school database, students, teachers, classes, and courses offered can be considered as entities.
Student
S1
Student S2
✓All the entities have their properties which are called attributes . s3
✓In the above example, Roll_id identifies each element of the table uniquely and hence, we can say that
STUDENT is a strong entity type.
E-R Model
ii. Weak Entity :
✓The weak entity is represented by a double rectangle.
Types of Attributes:
i. Key attribute
ii. Composite attribute
iii. Multi-valued attribute
iv. Derived attribute
E-R Model
Types of Attributes
i. Key Attribute :
✓It is represented by an ellipse with the text underlined.
✓The attribute which uniquely identifies each entity in the entity set is called key attribute.
Example:
✓Roll_No will be unique for each student.
ii. Composite Attribute :
✓ An attribute that is composed of many other attributes is known as a composite attribute.
✓The composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse.
E-R Model
iii. Multivalued Attribute :
✓An attribute can have more than one value.
✓The double oval is used to represent multivalued attribute.
Example:
✓student can have more than one phone number.
iv. Derived Attribute :
✓An attribute that can be derived from another attribute is known as a derived attribute.
✓It can be represented by a dashed ellipse.
✓A derived attribute is one whose value is dynamic and derived from another attribute.
Example:
✓A person's age changes over time and can be derived from another attribute like Date of birth.
E-R Model
iii. Relationship:
✓A relationship is used to describe the relation between entities.
✓Diamond or rhombus is used to represent the relationship.
✓Lines are used to link attributes to entity sets and entity sets to relationship sets.
❖ Cardinality of employee :1
❖ Cardinality of Department : N
E-R Model
Relationship set or cardinality:
Types of cardinality in between tables are:
✓one-to-one
✓one-to-many
✓many-to-one
✓many-to-many
E-R Model
Types of relationship:
i. One-to-One Relationship :
✓When a single instance of an entity is associated with a single instance of another entity then it is called
one to one relationship.
Example:
✓A male can marry to one female and a female can marry to one male. So the relationship will be one to
one.
Example:
✓A person has only one passport and a passport is given to one person.
E-R Model
ii. One-to-many relationship :
✓When only one instance of the entity on the left, and more than one instance of an entity on the right associates
with the relationship then this is known as a one-to-many relationship.
Example:
✓One Scientist can invent many inventions, but the invention is done by the only specific scientist.
✓Student enrolls for only one course, but a course can have many students.
E-R Model
iv. Many-to-many relationship :
✓When more than one instance of the entity on the left, and more than one instance of an entity on the right
associates with the relationship then it is known as a many-to-many relationship.
Example:
✓ student can be assigned to many projects and a project can be assigned to many students.
✓Employee can assign by many projects and project can have many employees.
Data Model
ER DIAGRAM FOR UNIVERSITY DATABASE
ER DIAGRAM FOR COMPANY DATABASE
Data Model
iv. Relational Model:
✓ This model was introduced by E.F Codd in 1970, and since then it has been the most widely used
database model.
✓ In this model, data is organized in two-dimensional tables and the relationship is maintained by
storing a common field.
✓ The basic structure of data in the relational model is tables.
✓ All the information related to a particular type is stored in rows of that table.
✓ Hence, tables are also known as relations in relational model.
✓ Popular Relational Database Management Systems:
1) IBM – DB2 and Informix Dynamic Server
2) Oracle – Oracle and RDB
3) Microsoft – SQL Server and Access
Data Model
iv. Relational Model:
Data Model
v.Object-Oriented Data Model:
✓ In this model both the data and the relationship are contained in a single structure that is known as an object in
this model.
✓ We can now store audio, video, pictures, and other types of data in databases, Although you can store video and
audio in relational DB, it is advised not to store them in the relational database.
Example:
✓ The Employee and Department are the two objects .
✓ Each object’s data and the relationships are there in a single unit.
✓ Here, the attributes of the employee, such as Name and Job_title, as well as
the methods that will be performed by that object, are all kept in a single
object.
✓ The two objects are linked by a common attribute, i.e., Department_id, as
well as communication between them will be accomplished by this common
id.
Introduction to the relational model
✓ In this model, the data is organized into a collection of two-dimensional inter-related tables, also known as
relations.
3. Attribute/Field : Column of the relation, depicting properties that define the relation.
4. Attribute Domain : Set of pre-defined atomic values that an attribute can take i.e., it describes the legal
values that an attribute can take.
6. Cardinality : It specifies the number of entities involved in the relation i.e., it is the total number of
rows present in the relation.
7. Relational Schema : It is the logical blueprint of the relation i.e., it describes the design and the structure of
the relation. It contains the table name, its attributes, and their types.
TABLE_NAME(ATTRIBUTE_1 TYPE_1, ATTRIBUTE_2 TYPE_2, ...)
Relational Model Concepts
7 Relational Instance : It is the collection of records present in the relation at a given time.
8 Relation Key : It is an attribute or a group of attributes that can be used to uniquely identify an entity
in a table or to determine the relationship between two tables. Relation keys can be of 7
different types:
Example:
Create table student ( Roll_No number(4) Not null, name varchar2(10) , Age number(4), Phone number(10));
✓ In the above example we have applied not null Roll_No column,whenever a record is entered using insert statement
Roll_No column should contain a value other than null.
Key constraints in DBMS
2. Unique:
✓ Some times we need to maintain only. Unique data in the column of a database table, this is possible by
using a Unique constraint.
✓ Unique constraint ensures that all values in a column are Unique.
Example:
Create table student ( Roll_No number(4) Unique, name varchar2(10) , Age number(4), Phone number(10));
✓ In the above example, as we have used unique constraint on ID column we are not supposed to enter the data
that is already present, simply no two ID values are same.
Key constraints in DBMS
3. Default:
✓ Default in SQL is used to add default data to the columns.
✓ When a column is specified as default with same value then all the rows will use the same value i.e., each and
every time while entering the data we need not enter that value.
✓ But default column value can be customised i.e., it can be over ridden when inserting a data for that row
based on the requirement.
Example:
Create table EMPLOYEE (id_no number(10) Not null, name varchar (25) Not null, company varchar (25) Default abc);
✓ As a result, whenever you insert a new row each time you need not enter a value for this default column that
is entering a column value for a default column is optional.
Key constraints in DBMS
4. Check:
✓ Check constraint ensures that the data entered by the user for that column is within the range of values or
possible values specified.
Example:
Create table STUDENT (Roll_No number(4) Unique, name varchar (25) not null, age number(2) check(age>=18));
✓ As we have used a check constraint as (age>=18) which means value entered by user for this age column while
inserting the data must be less than or equal to 18
Keys
5. Super Key:
✓ A super key is a set of attributes that can identify each tuple uniquely in the given relation.
✓ Super key may consist of any number of attributes.
Example:
✓ Consider the following Student schema-
✓ Given below are the examples of super keys since each set can uniquely identify each student in
the Student table-
-( roll , name , gender , age , address , class , section )
-( class , section , roll )
-(class , section , roll , gender )
-( name , address )
Keys
6. Candidate Key:
✓ A set of minimal attribute(s) that can identify each tuple uniquely in the given relation is called as a
candidate key.
✓ Candidate Key is a super key with no repeated attributes.
✓ The Primary key should be selected from the candidate keys.
Example:
✓ Consider the following Student schema-
✓ Given below are the examples of candidate keys since each set consists of minimal attributes required
to identify each student uniquely in the Student table-
-( class , section , roll )
-( name , address )
Keys
6. Candidate Key:
✓ The value of candidate key must always be unique.
✓ The value of candidate key can never be NULL.
✓ It is possible to have multiple candidate keys in a relation.
Keys
7.Primary Key :
✓ A primary key is a candidate key that the database designer selects while designing the database.
✓ It is a column or group of columns in a table that uniquely identify every row in that table.
✓ The Primary Key can’t be a duplicate meaning the same value can’t appear more than once in
the table.
Rules for defining Primary key:
✓ The value of primary key can never be NULL.
✓ The value of primary key must always be unique.
✓ The values of primary key can never be changed i.e. no updation is possible.
✓ The value of primary key must be assigned when inserting a record.
✓ A relation is allowed to have only one primary key.
Keys
Creating Primary Key :
✓ A particular column is made as a primary key column by using the primary key keyword
followed by the column name.
Example:
Create table EMP (Roll_No number(4), name varchar2(20), age number(4), gpa varchar2(10), Primary key (Roll_No));
✓ Here we have used the primary key on ID column then ID column must contain unique values
i.e., one ID cannot be used for another student.
Keys
8.Foreign Key:
✓ The foreign key constraint is a column or list of columns which points to the primary key column of
another table.
✓ The main purpose of the foreign key is only those values are allowed in the present table that will
match to the primary key column of another table.
Keys
From the above two tables, COURSE_ID is a primary key of the table STUDENT_DETAILS and also behaves as a foreign key
in STUDENT_MARKS.
Example:
(Reference Table)
Create table STUDENT_DETAILS (ROLL_NO number(10), NAME varchar2 (25), COURSE_ID varchar (10), primary key (COURSE_ID));
(Child table)
Create table STUDENT_MARKS (COURSE_ID varchar (10), MARKS number(10), references STUDENT_DETAILS (COURSE_ID ));
Keys
NOTE:
✓ Foreign key references the primary key of the table.
✓ Foreign key can take only those values which are present in the primary key of the referenced relation.
✓ Foreign key may have a name other than that of a primary key.
✓ Foreign key can take the NULL value.
✓ There is no restriction on a foreign key to be unique.
✓ In fact, foreign key is not unique most of the time.
✓ Referenced relation may also be called as the master table or primary table.
✓ Referencing relation may also be called as the foreign table.
Keys
Keys
9. Alternate Key:
✓ A table can have multiple choices for a primary key but only one can be set as the primary key. All the
keys which are not primary key are called an Alternate Key.
✓ Candidate keys that are left unimplemented or unused after implementing the primary key are called as
alternate keys.
Keys
10. Composite Key:
✓ Sometimes, a table might not have a single column/attribute that uniquely identifies all the records of a table. In
order to uniquely identify rows of a table, combination of two or more columns/attributes can be used.
✓ COMPOSITE KEY is a combination of two or more columns that uniquely identify rows in a table. The combination of
columns guarantees uniqueness, though individually uniqueness is not guaranteed.
✓ 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.
Keys
Relational algebra
✓ Relational database systems are expected to be equipped by a query language that can assist its user to
✓ There are two kinds of query languages, relational algebra and relational calculus.
✓ Relational algebra is a procedural query language, which takes instances of relations as input and yields
✓ Selects tuples that satisfy the given predicate from a relation. σ p (r)
✓ Where p stands for selection predicate and r stands for relation. p is prepositional logic formulae
which may use connectors like and, or and not. These terms may use relational operators like: =, ≠,
≥, < , >, ≤.
Example Output :
σsubject="database" (Books)) Selects tuples from books where subject is
'database'.
Example Output :
σ subject="database" and price="450" (Books) Selects tuples from books where subject is 'database' and
'price' is 450.
Relational algebra operations
ii.Project Operation (∏):
✓ Projects column(s) that satisfy given predicate.
Syntax
✓ Where a1, a2 , an are attribute names of relation r. Duplicate rows are automatically eliminated, as
relation is a set.
Example
∏subject, author (Books)
Output :
Selects and projects columns named as subject and author from relation Books.
Relational algebra operations
iii.Union Operation (∪):
Syntax
✓ Union operation performs binary union between two given
relations and is defined as: r ∪ s = { t | t ∈ r or t ∈ s}
✓ Where r and s are either database relations or relation
result set (temporary relation).
✓ For a union operation to be valid, the following conditions
must hold: Example
✓ r, s must have same number of attributes. ∏ author (Books) ∪ ∏ author (Articles)
r−s
✓ Finds all tuples that are present in r but not s.
Example
∏ author (Books) − ∏ author (Articles)
Output :
Results the name of authors who has written books but not articles.
Relational algebra operations
v.Cartesian Product (Χ):
✓ Combines information of two different relations into one.
Syntax
rΧs Syntax
r Χ s = { q t | q ∈ r and t ∈ s}
✓ Where r and s are relations and there output will be defined as:
Example
∏ author = 'tutorialspoint'(Books Χ Articles))
Output :
yields a relation as result which shows all books and articles written by tutorialspoint.
Relational algebra operations
vi.Rename operation ( ρ ):
✓ Results of relational algebra are also relations but without any name.
✓ The rename operation allows us to rename the output relation. rename operation is denoted with
small greek letter rho ρ
Syntax
ρ x (E)
✓ Where the result of expression E is saved with name of x.
Example
ρ x (E)
Relational Calculus
✓ Relational Calculus is non-procedural query language, that is, it tells what to do but never explains the
way, how to do it. Relational calculus exists in two forms:
i. Tuple relational calculus (TRC)
ii. Domain relational calculus (DRC)
Relational Calculus
i.Tuple relational calculus (TRC):
✓ Filtering variable ranges over tuples.
Syntax
{ T | Condition }
✓ Returns all tuples T that satisfies condition.
Example Output:
{ T.name | Author(T) AND T.article = 'database' } returns tuples with 'name' from Author
who has written article on 'database'.
✓ TRC can be quantified also. We can use Existential ( ∃ )and Universal Quantifiers ( ∀ ).
Example Output :
{ R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)} The query will yield the same result as
the previous one
Relational Calculus
ii. Domain relational calculus (DRC) :
✓ In DRC the filtering variable uses domain of attributes instead of entire tuple values (as done in
TRC, mentioned above).
Syntax
{ a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}
✓ where a1, a2 are attributes and P stands for formulae built by inner attributes.
Example
{< article, page, subject > | ∈ TutorialsPoint ∧ subject = 'database'}
Output:
Yields Article, Page and Subject from relation TutorialsPoint where Subject is database.
‘U’ T
K H
N A