BILAL DBMS UNIT-1 Notes
BILAL DBMS UNIT-1 Notes
Introduction and Data Base Design: Introduction to DBMS, applications of DBMS, database systems
versus file systems, view of data, Database users and administrators, database system structure.
Database Design- E-R diagrams, entities, attributes and entity sets, relationships and relationship sets,
additional features of the E-R model. The Relational Model: Introduction to the relational model,
logical database design: E-R to relational, relational algebra operations and basic queries, relational
calculus operators and basic queries.
✓ It takes variety of forms, including numeric data, text and voice and images.
1.2 Information:
✓ Data that have been processed in such a way as to increase the knowledge of the person
who uses the data.
1.3 Database:
✓ The Organized Collection of Data, which contains related information.
✓ 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.
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.
✓ 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.
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 databases in a geographically distributed manner.
4. Credit card For purchases on credit cards and generation of monthly statements.
transactions
5. Telecommunication For keeping records of calls made, generating monthly bills, maintaining
balances on prepaid calling cards, and storing information about the
communication networks.
6. Finance For storing information about holdings, sales, and purchases of financial
instruments such as stocks and bonds.
9. Human resources For information about employees, salaries, payroll taxes and benefits.
It is easy-to-use system to store general files It is used when security constraints are
which require less security and constraints. high.
User locates the physical address of the User is unaware of physical address where
files to access data . data is stored.
Integrity Problems:
-Hard to add new constraints or change existing ones.
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.
Security Problems:
-Not every user of the database system should be able to access all the data.
4. view of data:
✓ The three level of DBMS architecture is:
✓ The view level provides the “view of data” to the users and hides the irrelevant details such
as data relationship, database schema, constraints, security etc from the user.
✓ To fully understand the view of data, you must have a basic knowledge of 2 components
▪ Data Abstraction
Logical Level
Physical
Level
Mohammad Bilal J, Dept of IT,VCE
DBMS UNIT-I
✓ 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.
✓ You can get the complete data structure details at this level.
Example -1:
✓ When you are booking a train ticket, you are not concerned how data is processing at the
back end when you click “book ticket”.
✓ 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.
Example-2:
✓ 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.
Example:
✓ Schema helps the database users to understand the relationship between data.
a) Physical schema
b) logical schema
c) view schema
This schema allows data access to be customized at the level of individual users or groups of users.
Physical data independence: The ability to modify the physical schema without changing
logical schema
Logical data independence: The ability to modify the logical or conceptual schema without
changing application programs.
Example:
✓ 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.
i. Naive users
v. Specialized users
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.
✓ They are the computer professionals who writes the code for the application programs.
✓ These programs could be written in Programming languages such as Visual Basic, Java,
.net, php, C, etc.
✓ There are many database packages are available for this type of users.
✓ They interact with the system by writing SQL queries directly through the query
processor.
✓ They are the SQL programmers, who are going to deal directly with the database.
v. Specialized users:
✓ They are also sophisticated users who write specialized database applications that do
not fit into the traditional data processing framework.
✓ Tasks of DBA:
–Monitoring performance
❖ System DBA
❖ Database architect
❖ Application DBA
❖ Task-oriented DBA
❖ Performance analyst
❖ Cloud DBA
System DBA:
✓ In this role, the focus is on technical details of how the database is installed, configured
and modified. Typical tasks include the following:
▪ Installing new versions and ensuring appropriate storage and memory are
available for the DBMS etc.
Database architect:
✓ Primary responsibility is the design and implementation of new databases. Typical tasks
include the following:
Application DBA:
✓ Focus is on database design and the ongoing database support and administration for a
specific application.
✓ The application DBA is more likely an expert in writing and debugging complex SQL and
will understand the best ways to incorporate database requests into application
programs.
Task-oriented DBA:
✓ This specialized DBA focuses on a specific administrative task.
Performance analyst:
✓ The performance analyst focuses entirely on monitoring and improving the performance
of applications that access databases.
Cloud DBA:
✓ The cloud DBA understands the services the cloud provider offers, including backup and
security, to implement databases in the cloud.
✓ A database system is partitioned into 3-modules that deal with each of the responsibilities
of the overall system.
✓ The top part of the diagram refers to the various users of the database environment and
their interfaces.
✓ The lower part shows the internals of the DBMS responsible for storage of data and
processing of transactions.
✓ The functional components of a database system can be broadly divided into three
components:
▪ Query processor
▪ Storage manager
▪ Disk Storage
✓ It interprets the requests (queries) received from end user via an application program
into instructions.
▪ DDL interpreter
▪ DML compiler
DDL interpreter:
✓ It processes the DDL statements into a set of table containing meta data .
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.
✓ It is responsible for updating, storing, deleting, and retrieving data in the database.
✓ It maintains the consistency and integrity of the database by applying the constraints
and executing the DCL statements.
▪ Buffer manager
▪ File manager
▪ Transaction manager
Buffer Manager:
✓ It is responsible for fetching data from disk storage into main memory, and deciding
what data to cache in main memory.
File Manager:
✓ It manages the file space and the data structure used to represent information in the
database.
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.
▪ Data Files
▪ Data Dictionary
▪ Indices
Data Files:
It stores the data.
Data Dictionary:
It contains the information about the structure of any database.
Indices:
It provides faster retrieval of data item.
7.Database design
The design process consists of the following steps:
8.Data Model
✓ The Data Model gives us an idea of how the final system would look after it has been fully
implemented.
✓ 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.
✓ Types of Data Models in DBMS
i. Hierarchical Model
ii. Network Model
iii. Entity-Relationship Model
iv. Relational Model
v. Object-Oriented Data Model
✓ 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 added to the parent node.
✓ 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 sitemaps, and so on.
✓ In this model data is organized more like a graph, and are allowed to have more than one
parent node.
✓ Data is more related as more relationships are established in this database model.
✓ As the data is more related, hence accessing the data is also easier and fast.
✓ This was the most widely used database model, before Relational Model was introduced.
✓ It represent the relationships into pictorial form to make it easier for different stakeholders
to understand.
✓ This model is good to design a database, which can then be turned into tables in relational
model.
8.3.1 Entity-Type:
✓ Entity-Type is denoted by the rectangle box.
✓ 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
✓ All the entities have their properties which are called attributes .
S2
✓ Collection of similar types of entities known as an entity set.
s3
✓ For example, a Student set may contain all the students.
Types of Entities:
▪ Strong Entity
▪ Weak Entity
Strong Entity :
✓ It is represented using a single rectangle.
✓ Strong entity are those entity types which has a key attribute.
✓ 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.
Weak Entity :
✓ The weak entity is represented by a double rectangle.
✓ The weak entity doesn't contain any key attribute of its own.
8.3.2 Attribute:
✓ The attribute is used to describe the property of an entity.
Example:
Types of Attributes:
▪ Key attribute
▪ Composite attribute
▪ Multi-valued attribute
▪ Derived attribute
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:
✓ The composite attribute is represented by an ellipse, and those ellipses are connected
with an ellipse.
Example:
✓ 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.
9.3.3 Relationship:
✓ A relationship is used to describe the relation between entities.
✓ Lines are used to link attributes to entity sets and entity sets to relationship sets.
I. UNARY RELATIONSHIP:
✓ When there is only one entity set participating in a relation, the relationship is called as
unary relationship.
Example:
❖ Cardinality of employee :1
❖ Cardinality of Department : N
✓ one-to-one
✓ one-to-many
✓ many-to-one
✓ many-to-many
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.
Example:
✓ One Scientist can invent many inventions, but the invention is done by the only specific
scientist.
Example:
✓ Many students can study in a single college but a student cannot study in many colleges at
the same time.
✓ Student enrolls for only one course, but a course can have many students.
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.
✓ In this model, data is organized in two-dimensional tables and the relationship is maintained
by storing a common field.
✓ All the information related to a particular type is stored in rows of that table.
✓ 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 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.
i. Relation
ii. Tuple
iii. Attribute/Field
v. Degree
vi. Cardinality
3. Attribute/Field Column of the relation, depicting properties that define the relation.
4. Attribute Set of pre-defined atomic values that an attribute can take i.e., it describes
Domain 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 It is the logical blueprint of the relation i.e., it describes the design and the
Schema structure of the relation. It contains the table name, its attributes, and their
types.
✓ 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.
✓ These constraints are checked before performing any operation like insertion, deletion, or
updation on the data present in a relational database.
Domain Constraint: It specifies that every attribute is bound to have a value that lies inside a
specific range of values.
Key Constraint: It states that every relation must contain an attribute or a set of attributes that
can uniquely identify a tuple in that relation.
Referential Integrity Constraint: It is defined between two inter-related tables. It states that if a
given relation refers to a key attribute of a different or same table.
✓ Constraints ensure that the data entered by the user into columns must be within the
criteria specified by the condition.
i. Not Null
ii. Unique
iii. Default
iv. Check
v. Super key
x. Alternate key
i. Not Null:
✓ Once not null is applied to a particular column, you cannot enter null values to that
column.
✓ A not null constraint cannot be applied at table level
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.
ii. 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.
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.
iii. 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.
iv. 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.
v. Super Key:
✓ A super key is a set of attributes that can identify each tuple uniquely in the given relation.
Example:
Student ( roll , name , gender , age , address , class , section )
✓ 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 )
-( name , address )
Example:
✓ 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-
-( name , address )
vii.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.
✓ The values of primary key can never be changed i.e. no updation is possible.
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.
viii.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.
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));
Create table STUDENT_MARKS (COURSE_ID varchar (10), MARKS number(10), references STUDENT_DETAILS (COURSE_ID ));
NOTE:
✓ 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.
✓ Referenced relation may also be called as the master table or primary table.
✓ Candidate keys that are left unimplemented or unused after implementing the primary key
are called as alternate keys.
x. 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.
10.Relational algebra
✓ Relational database systems are expected to be equipped by a query language that can assist
its user to query the database instances.
✓ 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 instances of relations as output.
i. Select
ii. Project
iii. Union
v. Cartesian product
vi. Rename
✓ 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: =, ≠, ≥, < , >, ≤.
Syntax Example
Example
σ subject="database" and price="450" (Books)
Output : Selects tuples from books where subject is 'database' and 'price' is 450.
Syntax
∏ (r)
A1, A2, An
✓ Where a1, a2 , an are attribute names of relation r. Duplicate rows are automatically
eliminated, as relation is a set.
Example
∏ (Books)
subject, author
Output :
Selects and projects columns named as subject and author from relation Books.
✓ Where r and s are either database relations or relation result set (temporary relation).
Syntax Example
Output :
Projects the name of author who has either written a book or an article or both.
Syntax
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.
Syntax Syntax
rΧs r Χ s = { q t | q ∈ r and t ∈ s}
Example
∏ author = 'Raghu Ram Krishna'(Books Χ Articles))
Output :
yields a relation as result which shows all books and articles written by Raghu Ram Krishna'.
✓ The rename operation allows us to rename the output relation. rename operation is denoted
with small greek letter rho ρ
Syntax Example
ρ (E) ρ x (E)
x
Syntax Example
Output: 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
{ R| ∃T ∈ Authors(T.article='database' AND R.name=T.name)}
Output : The query will yield the same result as the previous one.
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 > | ∈ Technology ∧ subject = 'database'}
Output: Yields Article, Page and Subject from relation Technology where Subject is database.