0% found this document useful (0 votes)
13 views21 pages

DBMS Unit-1

Uploaded by

21x55a0510
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)
13 views21 pages

DBMS Unit-1

Uploaded by

21x55a0510
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/ 21

DATABASE

MANAGEMENT SYSTEM-
Database Management System
20A05401T-R20
Course Outcomes
After completion of the course, students will be able to
• Design a database for a real-world information system
• Define transactions that preserve the integrity of the database
• Generate tables for a database
• Organize the data to prevent redundancy
• Pose queries to retrieve the information from the database.

Syllabus:
Introduction: Database systems applications, Purpose of Database Systems, view of Data,
Database Languages, Relational Databases, Database Design, Data Storage and Querying,
Transaction Management, Database Architecture, Data Mining and Information Retrieval,
Specialty Databases, Database users and Administrators,
Introduction to Relational Model: Structure of Relational Databases, Database Schema,
Keys, Schema Diagrams, Relational Query Languages, Relational Operations

Introduction
What Is DATA?
Data can Be defined as Any (raw) facts about an object, that can be recorded in the form of
text, numbers, images, speech, audio, video … etc
Example: Student
Data or Attributes

What Is Information?
• Information is processing the data.
Example : Student

Information

What is Database
• It is a Collection of related data or Structured Information and it can be stored
Electronically in Computer System and Controlled by DBMS.
• Various types of Databases
– Traditional Database: Contains only Text & Numbers.
– Multimedia Database: Contains videos and audio, images….
– Geographical Info Database: Contains Satellite information
– Real Time Databases: product based databases such as Supermarket,
store…..

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
What is DBMS
20A05401T-R20
• It is a system or Program that manages a database.
• Manages means create and delete, modify, insert the related data in the database.
• Set of programs to access the data
• Database Management System, abbreviated as DBMS, is an effective way to store the
data when constraints are high and data maintenance and security are the primary
concern of the user.
Importance of DBMS
• Database management systems providing you a way to store and retrieve data
efficiently. And now we have a lot of data to store.
• Every transaction generates some data to be stored. e.g. you withdraw cash from
ATM. It has to be stored
• You buy stocks it has to be stored.
• You like something on Facebook, it has to be stored.
• You order something from Flipkart, it needs to be stored.
• You book a ticket that has to be stored.
• You send a WhatsApp message it has to be stored.
• Basically, everything today has some data that has to be stored.
• Database management systems provide you the way or framework to store and
process this huge amount of data efficiently.
Database-System Applications
• All database applications, old and new, share important common elements.
• The application is not a program performing some calculation.
• Database systems are used to manage collections of data that:
• are highly valuable,
• are relatively large, and
• are accessed by multiple users and applications, often at the same time.
• Structured Data
• Enterprise Information
– Sales: For customer, product, and purchase information.
– Accounting: For payments, receipts, account balances, assets, and other
accounting information.
– Human resources: For information about employees, salaries, payroll taxes,
and benefits, and for generation of paychecks.
• Manufacturing: production of items in factories, inventories of items in warehouses
and stores, and orders for items.
• Banking and Finance
– Banking: For customer information, accounts, loans, and banking
transactions.
– Credit card transactions: For purchases on credit cards and generation of
monthly statements.

– Finance: For storing information about holdings, sales, and purchases of


financial instruments such as stocks and bonds.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
–20A05401T-R20
Universities: For student information, course registrations, and grades,
results….
– Airlines: For reservations and schedule information. Airlines were among the
first to use databases in a geographically distributed manner.
– Telecommunication: For keeping records of calls, texts, and data usage,
generating monthly bills, maintaining balances on prepaid calling cards, and
storing information about the communication networks.
• Web-based services
– Social-media: For keeping records of users, connections between users
(friend/follows information), rating/like information about posts, etc.
– Online retailers: For keeping records of sales data and orders as for any
retailer, but also for tracking a user’s product views, search terms, etc.,
– Online advertisements: For keeping records of click history to enable
targeted advertisements, product suggestions, news articles, etc.
– Document databases: For maintaining collections of new articles, patents,
published research papers, etc.
– Navigation systems: For maintaining the locations of varies places of interest
along with the exact routes of roads, train systems, buses, etc.

• Modes of Database
There are two modes in which databases are used.
– Online transaction processing: where a large number of users use the database.
– Data analytics: the processing of data to draw conclusions, and infer rules or
decision procedures, which are then used to drive business decisions.
Purpose of Database Systems
• To understand the purpose of database systems, consider part of a university
organization that, among other data, keeps information about all instructors, students,
departments, and course offerings.
• One way to keep the information on a computer is to store it in operating-system files.
SREC, Dept of CSE
DATABASE
MANAGEMENT SYSTEM-
• To allow users to manipulate the information, the system has a number of application
20A05401T-R20
programs that manipulate the files, including programs to:
• Add new students, instructors, and courses.
• Register students for courses and generate class rosters.
• Assign grades to students, compute grade point averages (GPA), and generate
transcripts.
• Programmers develop these application programs to meet the needs of the university
• In the early days, database applications were built on top of file systems
• Drawbacks of using file systems to store data:
– 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 formats
– Integrity problems
• Integrity constraints (e.g. account balance > 0) become part of program
code
• Hard to add new constraints or change existing ones

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
–20A05401T-R20
Atomicity of updates
• Failures may leave database in an inconsistent state with partial
updates carried out
• E.g. transfer of funds from one account to another should either
complete or not happen at all
– Concurrent access by multiple users
• Concurrent accessed needed for performance
• Uncontrolled concurrent accesses can lead to inconsistencies
• E.g. two people reading a balance and updating it at the same
time
– Security problems

• Database systems offer solutions to all the above problems

File System Vs DBMS


• A file system is a process that manages how and where data on a storage disk,
typically a hard disk drive (HDD), is stored, accessed and managed.

File System DBMS


1. File System is a general, easy-to-use 1. Database management system is used
system to store general files which require when security constraints are high.
less security and constraints.
2. Data Redundancy is more in file 2. Data Redundancy is less in database
management system. management system.

3. Data Inconsistency is more in file system. 3. Data Inconsistency is less in database


management system.

4. Centralization is hard to get when it comes 4. Centralization is achieved in Database


to File Management System. Management System.
5. Security is low in File Management 5. Security is high in Database Management
System. System.

6. File Management System stores 6. Database Management System stores


unstructured data as isolated data structured data which have well defined
files/entities. constraints and interrelation.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
View of Data
20A05401T-R20

Levels of Abstraction
• Physical level describes how a record (e.g., customer) is stored.
• Logical level: describes data stored in database, and the relationships among the data.
type customer = record
name : string;
street : string;
city : integer;
end;
• View level: application programs hide details of data types. Views can also hide
information (e.g., salary) for security purposes.
Database Languages
• Data Definition Language.
– Create, Alter, Drop and Truncate
• Data Manipulation Language.
– Insert, Update, Delete
• Data Retrieval Language .
– Select
• Data Transaction Control Language.
– Commit, Rollback and Save point
• Data Control Language.
– Grant and Revoke
• A database system provides a Data-definition language (DDL) to specify the database
schema and a Data-manipulation language (DML) to express database queries and
updates.
• In practice, the data-definition and data-manipulation languages are not two separate
languages; instead, they simply form parts of a single database language, such as the
SQL language.
Data-Definition Language
• We specify a database schema by a set of definitions expressed by a special language
called a data-definition language (DDL).
• The DDL is used to specify additional properties of the data.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
• We specify the storage structure and access methods used by the database system by a
20A05401T-R20
set of statements in a special type of DDL called a data storage and definition
language.
• Schema – the logical structure of the database.
• e.g., the database consists of information about a set of customers and
accounts and the relationship between them)
• Physical schema: Database design at the physical level.
• Logical schema: Database design at the logical level.
• Instance – the actual content of the database at a particular point in time.
• Physical Data Independence – the ability to modify the physical schema without
changing the logical schema.
• Applications depend on the logical schema.
• In general, the interfaces between the various levels and components should be
well defined so that changes in some parts do not seriously influence others.

Database Design
• Database design mainly involves the design of the database schema.
• The database designer or data model use the conceptual-Design to specify the data
requirements of the database users and how the database will be structured to fulfill
these requirements.
• conceptual-design provides a detailed overview of the enterprise.
• Database design can be generally defined as a collection of tasks or processes that
enhance the designing, development, implementation, and maintenance of enterprise
data management system. Designing a proper database reduces the maintenance cost
thereby improving data consistency

• Database proceeds in two final design phases.


• Logical-design phase -High level Conceptual Schema
• Physical Design Phase - file organization and the internal storage structures
Data Models
• A collection of tools for describing
– data
SREC, Dept of CSE
DATABASE
MANAGEMENT SYSTEM-
– data relationships
20A05401T-R20
– data semantics
– data constraints
• Entity-Relationship model
• Relational model
• Other models:
– object-oriented model
– semi-structured data models
– Older models: network model and hierarchical
Entity-Relationship Model
• E-R model of real world
– Entities (objects)
• E.g. customers, accounts, bank branch
– Relationships between entities
• E.g. Account A-101 is held by customer Johnson
• Relationship set depositor associates customers with accounts

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
20A05401T-R20

Example of schema in the entity-relationship model

Relational Model
Customer-id Customer Customer Customer Account
Name street city Number
192-83-7465 Johnson Alma Palo Alto A-101
019-28-3746 Smith North Rye A-215
192-83-7465 Johnson Alma Palo Alto A-201
Example of tabular data in the relational model
321-12-3123
A Sample Relational Database Jones Main Harrison A-217
019-28-3746 Smith North Rye A-201

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
Database Engine
20A05401T-R20
• The functional components of a database system can be broadly divided into 3
– Storage Manager
– Query Processor
– Transaction Management.
Storage Manager
• The storage manager is important because databases typically require a large amount
of storage space.
• Corporate databases commonly range in size from hundreds of gigabytes to terabytes
of data.
• gigabyte is approximately 1 billion bytes, or 1000 megabytes (1024 MB).
• terabyte is approximately 1 trillion bytes or 1 million megabytes (1024 GB).
• The largest enterprises have databases that reach into the multi-petabyte range (a
petabyte is 1024 terabytes).
• The storage manager components include
• Integrity and Authorization manager
• Which satisfies the integrity Constraints.
• Transaction manager
• which ensures that the database remains in a consistent (correct) state
despite system failures, and that concurrent transaction executions
proceed without conflicts.
• File manager
• which manages the allocation of space on disk storage
• Buffer manager
• which is responsible for fetching data from disk storage into main
memory, and deciding what data to cache in main memory
Integrity Constraints
• Domain Constraints: A domain of possible values must be associated with every
attribute (for example, integer types, character types, date/time types).
• Referential Integrity: a value that appears in one relation for a given set of attributes
also appears in a certain set of attributes in another relation (referential integrity).
• Authorization: The type of access they are permitted on various data values in the
database.
• Read Authorization: which allows reading, but not modification of data.
• Insert Authorization: which allows insertion of new data, but not
modification of existing data.
• Update Authorization: which allows modification but not deletion of data.
• Delete Authorization: which allows deletion of data.
• The storage manager is responsible to the following tasks:
• interaction with the file manager
• efficient storing, retrieving and updating of data
• The storage manager implements several data structures as part of the physical system
implementation.
• Data files, which store the database itself.
• Data dictionary, which stores metadata about the structure of the database, in
particular the schema of the database.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
• Indices, which can provide fast access to data items. Like the index in this textbook.
20A05401T-R20
Query processor
• The query processor is important because it helps the database system to simplify and
facilitate access to data by writing Queries.
• The query processor components include:
– DDL interpreter
– DML compiler
– Query evaluation engine
• DDL interpreter, which interprets DDL statements and records the definitions in the
data dictionary.
• DML compiler, which translates DML statements in a query language into an
evaluation plan consisting of low-level instructions that the query-evaluation engine
understands.
• Query evaluation engine, which executes low-level instructions generated by the
DML compiler.
Transaction Manager
• A transaction is a collection of operations that performs a single logical function in a
database application
• Transaction-management component ensures that the database remains in a consistent
(correct) state despite system failures (e.g., power failures and operating system
crashes) and transaction failures.
• Concurrency-control manager controls the interaction among the concurrent
transactions, to ensure the consistency of the database.

Database Architecture

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
20A05401T-R20
• above Figure shows the architecture of a database system that runs on a centralized
server machine.
• The figure summarizes how different types of users interact with a database, and how
the different components of a database engine are connected to each other.
Application Architectures

▪ Two-tier architecture: E.g. client programs using ODBC/JDBC to communicate


with a database
▪ Three-tier architecture: E.g. web-based applications, and applications built using
“middleware”.
Two-tier architecture
• Now consider the architecture of applications that use databases as their backend.
• Database applications can be partitioned into two or three parts, as shown in Figure.
• Earlier-generation database applications used a two-tier architecture, where the
application resides at the client machine, and invokes database system functionality at
the server machine through query language statements.
Three-tier architecture
• In contrast, modern database applications use a three-tier architecture, where the
client machine acts as merely a front end and does not contain any direct database
calls;
• web browsers and mobile applications are the most commonly used application
clients today.
• The front end communicates with an application server. The application server,
• in turn, communicates with a database system to access data.
Database Users and Administrators
• Database Users are differentiated by the way they expect to interact with the system
• Application programmers – interact with system through DML calls
• Sophisticated users – form requests in a database query language
• Specialized users – write specialized database applications that do not fit into the
traditional data processing framework
• Naïve users – invoke one of the permanent application programs that have been
written previously
– E.g. people accessing database over the web, bank tellers, clerical staff

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
Database Administrators
20A05401T-R20
• Coordinates all the activities of the database system; the database administrator has a
good understanding of the enterprise’s information resources and needs.
• Database administrator's duties include:
– 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 relationship with users
– Monitoring performance and responding to changes in requirements

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
20A05401T-R20 Relational Database
Structure of Relational Databases
• A Relational database consists of a collection of tables, each of which is assigned a
unique name.
• For example, consider the instructor table of Figure 2.1, which stores information
about instructors.
• The table has four column headers: ID, name, dept name, and salary. Each row of this
table records information about an instructor, consisting of the instructor’s ID, name,
dept name, and salary.

Relational Database
• Figure 2.2 stores information about courses, consisting of a course id, title, dept name,
and credits, for each course.

• Figure 2.3 shows a third table, prereq, which stores the prerequisite courses for each
course.
• The table has two columns, course id and prereq id.
• Each row consists of a pair of course identifiers such that the second course is a
prerequisite for the first course.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
20A05401T-R20

• Relational database is in mathematical terminology


• Tuple is simply a sequence (or list) of values. The term tuple is used to refer to a row.
• Relation is used to refer to a table.
• attribute refers to a column of a table.
• relation instance to refer to a specific instance of a relation, that is, containing a
specific set of rows.
• The instance of instructor shown in Figure 2.1 has 12 tuples, corresponding to 12
instructors.
• The null value is a special value that signifies that the value is unknown or does not
exist.
Database Schema
• Database schema, which is the logical design of the database, and the database
instance, which is a snapshot of the data in the database at a given instant in time.
• A relation schema consists of a list of attributes and their corresponding domains.
• Consider the department relation of Figure . The schema for that relation is:
department (dept name, building, budget)

The Section schema is:


section (course_id, sec_id, semester, year, building, room_number, time_slot_id)

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
Keys
20A05401T-R20
• A key is an attribute or set of attributes which can be used to uniquely identify a
record or a row in a table.
S.No Regd Id S.Name S.Branch S.Mail id
1 CS501 Ramu CSE abc@gmai
2 CS502 raju CSE abcd@gmail
3 IT101 Adam IT adam123@gmail
4 EC401 Adam ECE adam11@gmail

Q: can you tell me What is the email address of Adam?


Q: can you tell me name of the student who is CSE Brach?

Why We need keys


• For Identifying any row of data in a table uniquely
• We can force identity of data and ensure integrity of data is maintained.
• To establish a relationship between tables and identifying relationship between tables.
• Example: sno in a table , Sno has unique values
Types of keys
• Super keys
• Candidate Key
• Primary key
• Foreign key
• Composite and compound key
Super key
• It is an attribute or set of attributes that can be used to identify row of the data in a
table.
• Example: Sno, regdno, Smail id,
sno + regid, regid + smailid, Smail id + sno….
Candidate key:
▪ minimal subset of super key which can be used to uniquely identify rows of data in a
table or record.
▪ Example: Sno, regdno, Smail id,
Example Table

S.No Regd Id S.Name S.Branch S.Mail id

1 CS501 Ramu CSE abc@gmai


2 CS502 raju CSE abcd@gmail
3 IT101 Adam IT adam123@gmail
4 EC401 Adam ECE adam11@gmail

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
20A05401T-R20
Primary Key
• Primary Key : it is an attribute which can be used to uniquely identify every row of
the data in a table.
• Sometimes Primary key is also called as candidate key .
• Primary key can be indicated as a underline in a query.
• Example: sid, regdno, mailid,
– pickup any one key as a primary key..
Foreign Key
• It is an attribute which can be used to provide a relationship with another table.
• Example: Sbranch
SBranch Branch Name HOD
CSE Comp.Science Michel
MECH Mechanical lakshman
IT Info.Tech ramaiah
ECE Ele.comm ashoke
Composite key
• Composite keys has multiple attributes.
• Any key with more than one attribute is called composite key.
• Example: super keys with morethan one attribute is called composite such as
(sno,regdno), (regdno, sbranch)
Compound key
• If a composite key has at-least one attribute which is foreign key then it is called as
compound key.
• Example: (regdid, brachcode) is compound key bcz branch is foreign key.

Schema Diagrams
• A database schema, along with primary key and foreign-key constraints, can be
depicted by schema diagrams.
• Figure 2.9 shows the schema diagram for our university organization.
• Each relation appears as a box, with the relation name at the top in blue and the
attributes listed inside the box.
• Primary-key attributes are shown underlined.
• Foreign-key constraints appear as arrows from the foreign-key attributes of the
referencing relation to the primary key of the referenced relation.
• We use a two-headed arrow, instead of a single-headed arrow, to indicate a referential
integrity constraint that is not a foreign-key constraints.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
20A05401T-R20

Relational Query Languages


• A query language is a language in which a user requests information from the
database.
• These languages are usually on a level higher than that of a standard programming
language.
• Query languages can be categorized as
– imperative,
– functional, or
– declarative.
Imperative query language
• An imperative query language, the user instructs the system to perform a specific
sequence of operations on the database to compute the desired result.
• Example: updated in the course of the computation.
functional and Declarative query language
• In functional query language, the computation is expressed as the evaluation of
functions that may operate on data in the database or on the results of other functions.
• In a declarative query language, the user describes the desired information without
giving a specific sequence of steps or function calls for obtaining that information.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
Relational20A05401T-R20
Algebra or operations
• The relational algebra consists of a set of operations that take one or two relations as
input and produce a new relation as their result.
• Two types of operations:
– Unary
– Binary
• unary operations, because they operate on one relation.
• Binary Operations because they operate on pairs of relations.
• Unary operations
– select,
– project, and
– Rename
• Binary operations
– union,
– Cartesian product, and
– set difference.
Select Operation
• The select operation selects tuples that satisfy a given predicate. We use the lowercase
Greek letter sigma (σ) to denote selection.
• The predicate appears as a subscript to σ.
• The argument relation is in parentheses after the σ.
• Notation: sc(R)
• Examples
• sSalary > 40000 (Employee)
• sname = “Smith” (Employee)
• The condition c can be =, <, , >, , <>.

SSN Name Salary


1234545 John 200000

5423341 Smith 600000


4352342 Fred 500000

sSalary > 400000 (Employee)


SSN Name Salary

5423341 Smith 600000

4352342 Fred 500000

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
20A05401T-R20

Examples
• Select the tuples where department is physics from instructor.
• find all instructors with salary greater than $90,000.
• find the instructors in Physics with a salary greater than $90,000.
• find all departments whose name is the same as their building name.

Projection (P)
• Eliminates columns, then removes duplicates.
• Projection is denoted by the uppercase Greek letter pi (π).
• Notation: πA1,…,An (R)
• Example: project social-security number and names:
• πID, name, salary (instructor)

Ex: Find the names of all instructors in the Physics department.

SREC, Dept of CSE


DATABASE
MANAGEMENT SYSTEM-
Rename 20A05401T-R20
• The rename is used o give unique names to the different occurrences of the same
relation.
• The rename operator, denoted by the lowercase Greek letter rho (ρ).

Union and & Difference


• R1  R2
• Example:
– ActiveEmployees  RetiredEmployees
– R1 – R2
• Example:
– AllEmployees -- RetiredEmployees
Cartesian Product
• Each tuple in R1 with each tuple in R2
• Notation: R1  R2
• Example:
– Employee  Dependents
• Very rare in practice; mainly used to express joins
Natural Join
• Notation: R1 || R2
• Meaning: R1 || R2 = PA(sC(R1  R2))
• Where:
• The selection sC checks equality of all common attributes
• The projection eliminates the duplicate common attributes
Natural Join Example:

SREC, Dept of CSE

You might also like