+ All Categories
Home > Documents > Lec-2 Describing & Storing Data in Database

Lec-2 Describing & Storing Data in Database

Date post: 04-Apr-2018
Category:
Upload: mohit-kumar
View: 231 times
Download: 0 times
Share this document with a friend

of 31

Transcript
  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    1/31

    Topics:

    1. DESCRIBING AND STORING DATAIN A DATABASE

    2. Queries in DBMS

    3. Structure of DBMS

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    2/31

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    3/31

    Database Schema (intension)

    description of the database is specified during

    database designDatabase State (extension of the schema)

    current state of the database

    actual data instances (occurrences) in a DB

    changes over time by updateInitially, a database is empty state with no data

    then, populate (load) the database with data

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    4/31

    Schemas, Instances and Database State

    Database Schema (meta-data): The description of a database.

    Includes descriptions of the database structure and the constraintsthat 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.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    5/31

    Schema diagram for UNIVERSITY database

    schema construct

    Known data:

    name of record types, data items

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    6/31

    Figure 1.2

    UNIVERSITY Database

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    7/31

    Data model

    Collection of high level data description without low level storagedetails 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)

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    8/31

    An example of Students relation is shown below

    Sid Name Login age

    53666 Jones jones@cs 18

    53688 Smith smith@ee 18

    53650 Smith smith@math 19

    53831 Madayan madayan@music 11

    53832 Mary mary@music 12

    Integrity constraint: Records in the relation should satisfy thiscondition

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    9/31

    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 modelIDS & IDMS

    similar to the hierarchical database with the implementation

    of many-to-many relationships

    Relational Model- DB2 , Informix,Oracle,Sybase, MS Access

    Object-Oriented ModelObjectstore & Versant

    Objects (collection of data items and procedures) and interactions between

    them.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    10/31

    External

    schema 1

    External

    schema 2

    External

    schema 3

    Conceptual schema

    Physical schema

    Disk

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    11/31

    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)

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    12/31

    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.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    13/31

    Describes several views of the database based on the databasemodel.

    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)

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    14/31

    A Database has

    One conceptual schema

    One Physical schema

    Many External Schema each tailored to aparticular group of users.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    15/31

    The data independence is the ability to change theschema at one level of a database system with outchanging the schema at a higher level.

    Logical data Independence

    Capacity to change the conceptual schema withouthaving to change the external schema, is called asthe logical data independence.

    With out changing the application programs, one canchange the logical schema.

    http://www.doag.de/orafaq/glossary/faqgloss.htmhttp://www.doag.de/orafaq/glossary/faqgloss.htmhttp://www.doag.de/orafaq/glossary/faqgloss.htm
  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    16/31

    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 canstill retrieve the data with little modification(relation name) and obtain the same answer.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    17/31

    Physical Data Independence

    There are occasions for changing the internalstructures for improved performance of theretrieval of data.

    Any change introduced to the internal schemaor physical schema will not affect the otherschemas.

    Change the internal schema without having tochange the conceptual schema

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    18/31

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    19/31

    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.)

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    20/31

    Database Languages and Interfaces

    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) andview 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).

    provide appropriate languages and interfaces for each category of users.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    21/31

    Data Manipulation Language (DML)

    Data Manipulation Language (DML) is a family ofcomputer languages used by computer programs and/ordatabase users to insert, delete and update data in adatabase.

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

    SELECT ... INTO INSERT UPDATE DELETE

    http://en.wikipedia.org/wiki/Computer_languagehttp://en.wikipedia.org/wiki/Computer_languagehttp://en.wikipedia.org/wiki/Databasehttp://en.wikipedia.org/wiki/Databasehttp://en.wikipedia.org/wiki/Select_(SQL)http://en.wikipedia.org/wiki/Insert_(SQL)http://en.wikipedia.org/wiki/Update_(SQL)http://en.wikipedia.org/wiki/Delete_(SQL)http://en.wikipedia.org/wiki/Delete_(SQL)http://en.wikipedia.org/wiki/Update_(SQL)http://en.wikipedia.org/wiki/Insert_(SQL)http://en.wikipedia.org/wiki/Select_(SQL)http://en.wikipedia.org/wiki/Databasehttp://en.wikipedia.org/wiki/Computer_language
  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    22/31

    Queries in DBMS

    Consider a sample University DatabaseSome 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 arecalled Queries.

    DBMS provides specialized language called QueryLanguage

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    23/31

    Relational Calculus is a formal query language basedon mathematical logic.

    Relational Algebra is another formal query languagebased on collection of Operators .

    DBMS takes great care to evaluate queries as efficiently

    as possible.Indexes can be used to speed up Queries.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    24/31

    Relational Calculus Relational calculus consists of two calculi, the

    tuple relational calculus and the domainrelational calculus, that are part of therelational model for databases

    provides a declarative way to specify databasequeries.

    This in contrast to the relational algebra which isalso part of the relational model but provides amore procedural way for specifying queries.

    http://en.wikipedia.org/wiki/Tuple_relational_calculushttp://en.wikipedia.org/wiki/Domain_relational_calculushttp://en.wikipedia.org/wiki/Domain_relational_calculushttp://en.wikipedia.org/wiki/Relational_modelhttp://en.wikipedia.org/wiki/Relational_algebrahttp://en.wikipedia.org/wiki/Relational_algebrahttp://en.wikipedia.org/wiki/Relational_modelhttp://en.wikipedia.org/wiki/Domain_relational_calculushttp://en.wikipedia.org/wiki/Domain_relational_calculushttp://en.wikipedia.org/wiki/Tuple_relational_calculus
  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    25/31

    Relational Algebra Relational algebras received little attention until

    the publication ofE.F. Codd's relational modelof data in 1970. Codd proposed such analgebra as a basis for database querylanguages

    The six primitive operators of Codd's algebra

    are the selection, theprojection, the Cartesianproduct(also called the cross productor crossjoin), the set union, the set difference, and therename

    http://en.wikipedia.org/wiki/Edgar_F._Coddhttp://en.wikipedia.org/wiki/Relational_modelhttp://en.wikipedia.org/wiki/Relational_modelhttp://en.wikipedia.org/wiki/Selection_(relational_algebra)http://en.wikipedia.org/wiki/Projection_(relational_algebra)http://en.wikipedia.org/wiki/Cartesian_producthttp://en.wikipedia.org/wiki/Cartesian_producthttp://en.wikipedia.org/wiki/Set_unionhttp://en.wikipedia.org/wiki/Set_differencehttp://en.wikipedia.org/wiki/Rename_(relational_algebra)http://en.wikipedia.org/wiki/Rename_(relational_algebra)http://en.wikipedia.org/wiki/Set_differencehttp://en.wikipedia.org/wiki/Set_unionhttp://en.wikipedia.org/wiki/Cartesian_producthttp://en.wikipedia.org/wiki/Cartesian_producthttp://en.wikipedia.org/wiki/Projection_(relational_algebra)http://en.wikipedia.org/wiki/Selection_(relational_algebra)http://en.wikipedia.org/wiki/Relational_modelhttp://en.wikipedia.org/wiki/Relational_modelhttp://en.wikipedia.org/wiki/Edgar_F._Codd
  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    26/31

    Queries

    Find all courses that Mary takes

    What happens behind the scene ? Query processor figures out how to answer the

    query efficiently.

    SELECT C.nameFROM Students S, Takes T, Courses CWHERE S.name=Mary and

    S.ssn = T.ssn and T.cid = C.cid

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    27/31

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    28/31

    Structure of a DBMS

    A typical DBMS has a layeredarchitecture.

    This is one of several possible

    architectures; each system has its ownvariations.

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    29/31

    Webforms Application front

    ends

    SQL interface

    Plan executor

    Operator Evaluator Optimizer

    parserShows interaction

    Query EvaluationEngine

    TransactionManager

    Lock manager

    Files and Access

    Buffer Manager

    Disk space

    Manager

    Recovery

    Manager

    Index Files

    Data FilesSystem catalog

    Shows references

    Database

    Architecture of DBMS

    SQL commands

    Concurrency Control

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    30/31

    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 evaluatingquery

    The code that implements query lies above file and access method

    layer in which heap files are managed

  • 7/29/2019 Lec-2 Describing & Storing Data in Database

    31/31

    Below it is buffer manager which handles read requests of files

    from disk to memoryThe 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.


Recommended