Database Systems

53
 Database Systems GCE (A/L) ICT Training for Teachers 1

description

Database Systems

Transcript of Database Systems

  • Database Systems

    GCE (A/L) ICT Training for Teachers 1

  • Contact Persons

    Name : Buddhika H. Kasthuriarachchy

    Email : [email protected]

    Phone : 0112 413900 ext: 4301

    Mobile : 0773607507

    GCE (A/L) ICT Training for Teachers 2

  • Recommended Reading

    https://sites.google.com/site/ictalnie/

    Google user name : ictalnie2011

    Password : ictalniepython

    Fundamentals of Database Systems (5th

    Edition) Ramez Elmasri /Shamkant B. Navathe

    Database Management Systems (2nd

    Edition) - Raghu Ramakrishna

    /Johannes Gehrke

    GCE (A/L) ICT Training for Teachers 3

  • Introduction

    A Database is a collection of related data

    Data: known fact that can be recorded and have implicit meaning

    Eg : names, telephone numbers, student marks, etc

    GCE (A/L) ICT Training for Teachers 4

  • Introduction

    Database Management System(DBMS) is a collection of programs that enables

    users to create and maintain databases.

    Database System = database + DBMS

    GCE (A/L) ICT Training for Teachers 5

  • File Systems

    Before Mid 60s

    Operating Systems files provide the basic means of storing information.

    Files are sufficient for applications requiring small amounts of data &

    mainly single-user applications.

    GCE (A/L) ICT Training for Teachers 6

  • Database Systems vs File Systems

    Problems with file systems

    Data redundancy

    Integrity issues

    Required knowledge of storage details

    No standard language

    Files only provide sequential access

    Basic security capabilities (read, write, execute)

    GCE (A/L) ICT Training for Teachers 7

  • Evolution of Database Models

    First Generation

    Hierarchical & Network Model

    Second Generation

    Relational Model

    Third Generation

    Object Relational Model

    Object Oriented

    XML-DB

    GCE (A/L) ICT Training for Teachers 8

  • Evolution of Database Models

    In early 1960s, Charles Bachman proposed the Network Data Model

    In the late 1960s, IBM developed Information Management System (IMS) based on the Hierarchical Data Model

    In 1970, E.F. Codd of IBM - San Jose Research Laboratory, proposed the Relational Data Model

    GCE (A/L) ICT Training for Teachers 9

  • Relational Database Model

    Relation can be thought as a table of values

    Each row in the table represents a collection of related data

    Row is called a tuple

    Column header is called an attribute

    Table is called the relation

    GCE (A/L) ICT Training for Teachers 10

  • ANSI SPARC 3 Level Architecture

    External schema

    Conceptual/Logical schema

    Internal/Physical schema

    Mapping

    External conceptual mapping

    Conceptual physical mapping

    Data independence

    Logical

    Physical

    GCE (A/L) ICT Training for Teachers 11

  • ANSI SPARC 3 Level Architecture

    GCE (A/L) ICT Training for Teachers 12

  • External Schema

    Describe the database as it is seen by the user, and the user applications.

    Describe the part of the database that a particular user group is interested in and

    hides the rest of the database

    GCE (A/L) ICT Training for Teachers 13

  • Conceptual/Logical Schema

    Describe the structure of the whole database

    GCE (A/L) ICT Training for Teachers 14

  • Internal/Physical Schema

    Describes the physical storage structure of the database

    GCE (A/L) ICT Training for Teachers 15

  • Mapping

    The process of transforming requests and results between levels

    There are two types of mapping. External-Conceptual Mapping

    Conceptual-Internal Mapping

    GCE (A/L) ICT Training for Teachers 16

  • Data Independence

    The capacity to change the schema at one level of a database system without

    having to change the schema at the

    next higher level

    There are two types of data independence

    1.Logical data independence

    2.Physical data independence

    GCE (A/L) ICT Training for Teachers 17

  • DATABASE DESIGN PROCESS

    GCE (A/L) ICT Training for Teachers 18

  • Database Designing Steps

    Requirements Analysis

    Conceptual Database Design

    Logical Database Design

    Schema Refinement

    Physical Database Designing

    Security Design

    GCE (A/L) ICT Training for Teachers 19

  • Conceptual Database Design

    In this step, a high-level conceptual model is designed encapsulating the data requirements

    Entity-Relationship (ER) Model is a very popular & widely used conceptual model

    GCE (A/L) ICT Training for Teachers 20

  • Entity Relationship Model

    An entity is an object in the real world

    A collection of similar entities is called an entity set.

    Graphically,

    GCE (A/L) ICT Training for Teachers 21

    ENTITY

  • Entity Relationship Model

    An entity is described using a set of attributes.

    Graphically,

    For each attribute, a domain of possible values for the attribute needs to be

    defined

    GCE (A/L) ICT Training for Teachers 22

    Attribute

  • Entity Relationship Model

    Attributes containing multiple values are called multivalued attributes.

    Graphically,

    GCE (A/L) ICT Training for Teachers 23

    EMPLOYEE

    first_nameother_names

    surname

  • Entity Relationship Model

    Composite Attributes can be divided in to smaller subparts

    Graphically,

    GCE (A/L) ICT Training for Teachers 24

    Name

    First

    Middle

    Last

  • Entity Relationship Model

    Complex attributes

    Derived attributes and stored attributes

    GCE (A/L) ICT Training for Teachers 25

  • Relationship

    A relationship is an association among two or more entities

    A relationship can have descriptive attributes used to record information about the relationship

    GCE (A/L) ICT Training for Teachers 26

    Relationship name

    Relationship name

    Descriptive Attribute

  • Relationship

    Participation constraint specifies the fact that the relationship is required for

    every entity of the entity set.

    The relationship set has either total or partial participation

    Graphically, bold line represents a total participation

    GCE (A/L) ICT Training for Teachers 27

  • Degree of a Relationship is the number of participating entity types.

    A relation type of degree two is called binary, and one of degree three is

    called ternary

    GCE (A/L) ICT Training for Teachers 28

  • The cardinality ratio for a binary relationship specifies the number of

    relationship instances that an entity can

    participate in.

    There are three types of cardinality ratios for binary relationships. They are

    one-to-one, one-to-many (many-to-

    one) and many-to-many.

    GCE (A/L) ICT Training for Teachers 29

  • 1:1

    1:M

    M:1

    GCE (A/L) ICT Training for Teachers 30

    works

    inEMPLOYEE DEPARTMENT

    works

    inEMPLOYEE DEPARTMENT

    works

    inEMPLOYEE DEPARTMENT

    1 1

    1 M

    M 1

  • M:M

    GCE (A/L) ICT Training for Teachers 31

    works

    inEMPLOYEE DEPARTMENT

    M N

  • Logical Database Design

    ER Relational Mapping

    GCE (A/L) ICT Training for Teachers 32

  • Relational Model

    The basic construct of the relational model is the relation.

    A relation consists of

    relation schema

    relation instance

    GCE (A/L) ICT Training for Teachers 33

  • Relation Schema = relation name + {name of each field: domain of each

    field}

    COURSE (course_no: integer, title:

    string, credits: integer, year: integer,

    semester: integer)

    Relation Instance = set of tuples

    GCE (A/L) ICT Training for Teachers 34

  • A relational database is a collection of relations with distinct relation names

    Integrity constraint is a rule (or check) that is enforced by the DBMS to ensure

    that incorrect data is not stored in the

    database

    GCE (A/L) ICT Training for Teachers 35

  • Domain constraints

    Key Constraints

    Entity integrity constraints

    Referential integrity constraints

    Other constraints

    GCE (A/L) ICT Training for Teachers 36

  • Domain Constraints

    Domain constraints: specify that each attribute A must be an atomic value from the

    domain of A.

    Atomic value: That is, the value is non divisible into components

    Therefore, relational model doesnt allow multi-valued attributes or composite attributes!

    Relational database provides data types to specify valid domains.

    GCE (A/L) ICT Training for Teachers 37

  • Key Constraints

    Super key Suppose that we denote one such subset of

    attributes by SKi

    For any two distinct tuples t1 and t2 in a relation state r of R

    t1[SK] t2[SK]

    SK is called a superkey of the relation

    Specifies a uniqueness constraint

    Every relation has at least one default superkey

    GCE (A/L) ICT Training for Teachers 38

  • Key Constraints

    Key A key K of a relation schema R is a superkey of

    R

    Removing any attribute A from K leaves a set of attributes K' that is not a superkey of R any

    more

    It is a minimal superkey

    A superkey from which we cannot remove any attributes and still have the uniqueness constraint

    Eg:

    {SSN, Name, Age} is a superkey but not a key

    The property is time-invariant:

    GCE (A/L) ICT Training for Teachers 39

  • Key Constraints

    Candidate key A relation schema may have more than one

    key

    Each key is called a candidate key

    Primary key A candidate key

    values are used to identify tuples in the relation

    Better to choose a primary key with a single attribute or a small number of attributes

    The primary key of a relation schema are underlined

    GCE (A/L) ICT Training for Teachers 40

  • Key Constraints

    Alternate key In the candidate key the key which is not

    primary key is the alternate key.

    GCE (A/L) ICT Training for Teachers 41

  • Entity Integrity Constraints

    No primary key value can be null

    This is because the primary key value is used to identify individual tuples in a

    relation

    GCE (A/L) ICT Training for Teachers 42

  • Referential Integrity Constraints

    Specified between two relations

    Used to maintain the consistency among tuples in the two relations.

    A tuple in one relation that refers to another relation must refer to an

    existing tuple in that relation

    GCE (A/L) ICT Training for Teachers 43

  • ER to Relational Mapping

    Entity

    Simple Attributes

    Primary Key

    Composite attributes

    Relationships

    1:1

    1:M or M:1

    M:N

    Nry

    GCE (A/L) ICT Training for Teachers 44

  • ER to Relational Mapping

    Descriptive attrbutes

    Multivalued attributes

    GCE (A/L) ICT Training for Teachers 45

  • SCHEMA REFINEMENT

    GCE (A/L) ICT Training for Teachers 46

  • Conceptual Modeling is a subjective process

    Therefore, the schema after the logical database design phase may not be very good (contain redundancies)

    However, there are formalisms to ensure that the schema is good.

    This process is called Normalization

    GCE (A/L) ICT Training for Teachers 47

  • STRUCTURED QUERY

    LANGUAGE (SQL)

    GCE (A/L) ICT Training for Teachers 48

  • Data Definition Language

    The main SQL command for data definition is the CREATE statement

    Can be used to create schemas, tables, domains, etc

    GCE (A/L) ICT Training for Teachers 49

  • Data Definition Language

    CREATE TABLE My_table(

    my_field1 INT,

    my_field2 VARCHAR(50),

    my_field3 DATE NOT NULL,

    PRIMARY KEY (my_field1, my_field2)

    );

    ALTER TABLE My_table ADD my_field4

    NUMBER(3) NOT NULL;

    TRUNCATE TABLE My_table;

    DROP TABLE My_table;

    GCE (A/L) ICT Training for Teachers 50

  • Data Control Language

    GRANT - gives user's access privileges to database

    REVOKE - withdraw access privileges given with the GRANT command

    GCE (A/L) ICT Training for Teachers 51

  • Data Control Language

    GRANT SELECT, UPDATE ON My_table TO some_user, another_user;

    REVOKE SELECT, UPDATE ON My_table FROM some_user,

    another_user;

    GCE (A/L) ICT Training for Teachers 52

  • Data Manipulation Language

    Select

    Insert

    Update

    Delete

    GCE (A/L) ICT Training for Teachers 53