You are on page 1of 31

Topics:

1. DESCRIBING AND STORING DATA

IN A DATABASE
2. Queries in DBMS 3. Structure of DBMS

Database Schema (intension)


description of the database is specified during database design

Database State (extension of the schema)


current state of the database

actual data instances (occurrences) in a DB


changes over time by update

Initially, a database is empty state with no data then, populate (load) the database with data

Schemas, Instances and Database State


Database Schema (meta-data): The description of a database. Includes descriptions of the database structure and the constraints that should hold on the database. Schema Diagram: A diagrammatic display of (some aspects of ) a database schema.

Database Instance: The actual data stored in a database at a particular moment in time. Also called database state ( or occurrence, snapshot)
The database schema changes very infrequently. The database state changes every time the database is updated.

Schema diagram for UNIVERSITY database

schema construct

Known data: name of record types, data items

Figure 1.2 UNIVERSITY Database

Data model
Collection of high level data description without low level storage
details eg Relational data model Semantic data model describes a real application scenario. Eg: Entity relationship model

Relational model
Relations called as records Data are described as Schema Schema specifies its name, name of the field and type of each field. Eg: Students (Sid:String,name:String,login:String,age:integer)

An example of Students relation is shown below


Sid
53666 53688 53650 53831 53832

Name
Jones Smith Smith Madayan Mary

Login
jones@cs smith@ee smith@math madayan@music mary@music

age
18 18 19 11 12

Integrity constraint: Records in the relation should satisfy this


condition

Other Data Models


Hierarchical model IMS DBMS of IBM Trees of records: one-to-many relationships Limitations: Requires duplicating records (e.g. many-to-many relationship)
Network model IDS & IDMS similar to the hierarchical database with the implementation of many-to-many relationships Relational Model- DB2 , Informix,Oracle,Sybase, MS Access Object-Oriented Model Objectstore & Versant Objects (collection of data items and procedures) and interactions between them.

External schema 1

External schema 2

External schema 3

Conceptual schema

Physical schema

Disk

Describes the stored data in terms of the data model of the DBMS. This leads to conceptual database design. Also called as logical schema Represents data as a set tables. DBMS maps from conceptual schema to physical schema Example: Student(RegNo:Integer, Name:String, Sem:Integer, Branch:String) Faculty(Fid:Integer, FName:String, Salary:Float) Course(CourseNo:Integer, CName:String, Credit:Integer, Dept:String) Section(SecId:Integer, CourseNo:Integer, Sem:Integer, Year:Integer, Instructor:String) GradeReport(RegNo:Integer, SecId:Integer, Grade:Char)

Describes the actual storage details of the relations described in conceptual schema. Creates Indexes on First Column of Students, Faculty and Course relations. This leads to the physical database design. Physical schema specifies additional storage devices Describes how the relations described in conceptual schema are stored on secondary storage devices such as disks and tapes.

Describes several views of the database based on the database model.


Several external schemas are possible for a single database. Each view is based upon the user requirements. Data access to be customized at a level of individual users or groups

of users Each conceptual schema consist of collection of one or more views.

Example: StdGrade(RegNo:Integer, Name:String, Sem:Integer, Grade:Char)

A Database has
One conceptual schema One Physical schema

Many External Schema each tailored to a

particular group of users.

The data independence is the ability to change the schema at one level of a database system with out changing the schema at a higher level. Logical data Independence Capacity to change the conceptual schema without having to change the external schema, is called as the logical data independence. With out changing the application programs, one can change the logical schema.

Example

Suppose the Faculty relation is modified as: Faculty_Public(Fid:Integer, FName:String, Office:Integer) Faculty_Private(Fid:Integer, Salary:Float) Any view designed before this modification can still retrieve the data with little modification (relation name) and obtain the same answer.

Physical Data Independence


There are occasions for changing the internal

structures for improved performance of the retrieval of data.

Any change introduced to the internal schema

or physical schema will not affect the other schemas.

Change the internal schema without having to

change the conceptual schema

Database Languages
DDL Data Definition Language
SDL Storage Definition Language VDL View Definition Language DML Data Manipulation Language

(For data manipulations like insertion, deletion, update, retrieval etc.)

Database Languages and Interfaces


provide appropriate languages and interfaces for each category of users.

Data Definition Language (DDL) Used by the DBA and database designers to specify the conceptual schema of a database. In many DBMSs, the DDL is also used to define internal and external schemas (views).

In some DBMSs, separate storage definition language (SDL) and view definition language (VDL) are used to define internal and external schemas. Data Manipulation Language (DML) Used to specify database retrievals and updates (insertion, deletion, modifications)
- Alternatively, stand-alone DML commands can be applied directly (query language).

Data Manipulation Language (DML)


Data Manipulation Language (DML) is a family of

computer languages used by computer programs and/or database users to insert, delete and update data in a database.

Read-only querying, i.e. SELECT, of this data is a part of

DML

SELECT ... INTO INSERT UPDATE DELETE

Queries in DBMS
Consider a sample University Database Some questions user might ask: 1. What is the name & address of student with ENO = 06701442010 ? 2. How many students are enrolled in BBA 108? 3. How many students have more than 70% ? Such questions involving the data stored in a DBMS are called Queries. DBMS provides specialized language called Query Language

Relational Calculus is a formal query language based on mathematical logic. Relational Algebra is another formal query language based on collection of Operators .
DBMS takes great care to evaluate queries as efficiently as possible. Indexes can be used to speed up Queries.

Relational Calculus
Relational calculus consists of two calculi, the

tuple relational calculus and the domain relational calculus, that are part of the relational model for databases provides a declarative way to specify database queries.

This in contrast to the relational algebra which is also part of the relational model but provides a more procedural way for specifying queries.

Relational Algebra
Relational algebras received little attention until

the publication of E.F. Codd's relational model of data in 1970. Codd proposed such an algebra as a basis for database query languages The six primitive operators of Codd's algebra are the selection, the projection, the Cartesian product (also called the cross product or cross join), the set union, the set difference, and the rename

Queries
Find all courses that Mary takes

SELECT C.name FROM Students S, Takes T, Courses C WHERE S.name=Mary and S.ssn = T.ssn and T.cid = C.cid
What happens behind the scene ? Query processor figures out how to answer the query efficiently.

Structure of a DBMS
A typical DBMS has a layered architecture. This is one of several possible architectures; each system has its own variations.

Architecture of DBMS
Webforms Application front ends
SQL commands

SQL interface

Plan executor Operator Evaluator

parser Optimizer

Shows interaction

Query Evaluation Engine Transaction Manager Files and Access Buffer Manager Lock manager Concurrency Control Disk space Manager

Recovery Manager

Index Files System catalog Data Files

Shows references

Database

DBMS accepts SQL commands generated from variety of user interfaces Query is parsed and then presented to Query optimizer An execution plan is produced which is a blueprint for evaluating query The code that implements query lies above file and access method layer in which heap files are managed

Below it is buffer manager which handles read requests of files from disk to memory The lowest layer is Disk Space Manager DBMS components associated with concurrency control and crash recovery includes: Transaction Manager which ensures transaction request and schedules Lock Manager which handles locks grant and release on data

items
Recovery Manager which maintains log and restores system to consistent state after system crash.

You might also like