You are on page 1of 26

Database & RDBMS concepts: Data, Database & database Systems

What is Data?
A representation of facts or instruction in a form suitable for communication - IBM Dictionary

What is a Database?
Is a repository for stored data - C.J.Date

What is a database system?


An integrated and shared repository for stored data or collection of stored operational data used by application systems of some particular enterprise. Or Nothing more than a computer-based record keeping system.

Types of Database System


Hierarchical Network Relational

Copyright 2004, Cognizant Academy, All Rights Reserved

Database & RDBMS concepts: Data, Database & database Systems


Characteristics of Hierarchical Database
Can be visualized an upside down tree of data
a single table acts as the "root" (Parent)of the database from which other tables "branch(Children) out Child may only have one parent but a parent can have multiple children This child/parent rule assures that data is systematically accessible

Redundancy would occur because hierarchical databases handle one-tomany relationships well but do not handle many-to-many relationships well
Copyright 2004, Cognizant Academy, All Rights Reserved

Hierarchical Database

Database & RDBMS concepts: Data, Database & database Systems


Characteristics of Network Database
Child tables were allowed to have more than one parent
Network model supports many-to-many relationships The Network model solves the problem of data redundancy by representing relationships in terms of sets rather than hierarchy

Copyright 2004, Cognizant Academy, All Rights Reserved

Database & RDBMS concepts: Data, Database & database Systems


Characteristics of Relational Database
The concept of a table in which all data is stored The database is represented in terms of Entities, Relations and Attributes. Database is a collection of tables , constraints
Invoices
C#

C Name

C Addr

Customers

Sold To

I#

C#

Dat e

Am t

Relational Database
Copyright 2004, Cognizant Academy, All Rights Reserved 4

Database & RDBMS concepts: Data, Database & database Systems


Advantages of Database systems over File Management System are:
Data redundancy Multiple views Shared data Data independence (logical/physical) Data dictionary Search versatility Cost effective Security & Control Recovery restart & Backup Concurrency

Copyright 2004, Cognizant Academy, All Rights Reserved

Database & RDBMS concepts: Relational Properties & Terminology


Relation is a mathematical term for a table - Hence Relational database is perceived by the users as a set of tables.
All data values are atomic. Entries in columns are from the same domain Sequence of rows (T-B) is insignificant Each row is unique Sequence of columns (L-R) is insignificant

Relation : A table or File Tuple : Row contains an entry for each attribute Attributes : Columns or the characteristics that define the entity Domain: A range of values (or Pool) Entity : Some object about which we wish to store information Null : Represents an unknown value Atomic : Smallest unit of data; the individual data value
Copyright 2004, Cognizant Academy, All Rights Reserved 6

Database & RDBMS concepts:E-R Model


Entity-Relationship model is a logical representation of data for a business area Represented as entities, relationship between entities and attributes of both relationships and entities E-R models are outputs of analysis phase i.e they are conceptual data models expressed in the form of an E-R diagram

Copyright 2004, Cognizant Academy, All Rights Reserved

Database & RDBMS concepts: Normalization (1NF 5NF)


Normalization is done to bring the design of database to a standardized mode
1NF : All entities must have a unique identifier, or key, that can be composed of one or more attributes. All attributes must be atomic and non repeating. 2NF : Partial functional dependencies removed - all attributes that are not a part of the key must depend on the entire key for that entity. 3NF : Transitive dependencies removed - attributes that are not a part of the key must not depend on any non-key attribute. 4NF : Multi valued dependencies removed 5NF : Remaining anomalies removed

Copyright 2004, Cognizant Academy, All Rights Reserved

Database & RDBMS concepts: Types of Integrity


Entity Integrity: Rule states that no column that is part of a primary key can have a null value Referential Integrity: Rule states that every foreign key in the first table must either match a primary key value in the second table or must be wholly null Domain Integrity: Integrity of information allowed in column

Copyright 2004, Cognizant Academy, All Rights Reserved

DB2 Overview : DB2 Internal structure


CICS TSO IMS System Services
Active Logs

Relational Data Systems


DB2 Utilities

DB2 Optimizer

Data Manager Buffer Manager

D D F

Buffer Pools

VSAM Media Manager


DB2 Table Data
DB2 Directory

IRLM

DB2 Catalog
10

Copyright 2004, Cognizant Academy, All Rights Reserved

DB2 objects and Data types: STOGROUP


STOrage GROUP
It is a collection of direct access volumes, all of the same device type The option is defined as a part of tablespace definition When a given space needs to be extended, storage is acquired from the appropriate stogroup

STORAGE GROUP DATA BASE(S) TABLESPACE(S) TABLE(S) VIEW(S)

INDEX

Copyright 2004, Cognizant Academy, All Rights Reserved

11

DB2 objects and Data types : Database


DATABASE
It is a collection of logically related objects - like Tablespaces, Indexspaces, Tables etc. A STOGROUP & BUFFERPOOL (is buffer area used to maintain recently accessed table and index pages) must be defined for each database.

A database may occupy more than one disk space


In a given database, all the spaces need not have the same stogroup

Copyright 2004, Cognizant Academy, All Rights Reserved

12

DB2 objects and Data types: Tablespaces


TABLESPACES
Logical address space on secondary storage to hold one or more tables A SPACE is basically an extendable collection of pages with each page of size 4K or 32K bytes. It is the storage unit for recovery and reorganizing purpose Three Type of Tablespaces - Simple, Partitioned & Segmented

Simple Tablespace
Can contain more than one stored table Depending on application, storing more than one Table might enable faster retrieval for joins using these tables Usually only one table is preferred. This is because a single page can contain rows from all tables defined in the database. LOAD with replace option deletes all data

Copyright 2004, Cognizant Academy, All Rights Reserved

13

DB2 objects and Data types: Tablespaces


Segmented Tablespace
Can contain multiple tables.The tables are stored in different segments.

A Segment consists of a logically contiguous set of n pages.


Segsize parameter decides the allocation size for the tablespace No segment is allowed to contain records for more than one table Sequential access to a particular table is more efficient Mass Delete is much more efficient than in any other Tablespace Reorganizing the tablespace will restore every table to its clustered order Lock Table on table, locks only the table, not the entire tablespace If a table is dropped, the space for that table can be reclaimed with minimum reorg

Copyright 2004, Cognizant Academy, All Rights Reserved

14

DB2 objects and Data types: Tablespaces


Partitioned Tablespaces
Primarily used for very large tables

Only one table in a partitioned TS; 1 to 64 partitions/TS


Numpart parameter specifies the no. of partitions It is partitioned in accordance with value ranges for single or a combination of columns. Hence these column(s) cannot be updated

Individual partitions can be independently recovered and reorganized


Different partitions can be stored on different storage groups for efficient access.

Copyright 2004, Cognizant Academy, All Rights Reserved

15

DB2 objects and Data types: Tables, Views & Index


Tables store the data in the form of
Columns of values attached to a specific datatype with allowable value constraints A row for each record. Columns
EMPNO 10 20 30 FIRSTNME CHRISTINE MICHAEL SALLY MIDINIT LASTNAME I HAAS L THOMPSON A KWAN WORKDEPT A00 B01 C01

Rows

A View is a subset of columns that are open for a specific purpose. It can be a join of more than one tables. Indexes are based on the values of data in one or more columns. An index is an object that is separate from the data in the table. Indexes are used to enhance performance. These are discussed in detail further in the course.
Copyright 2004, Cognizant Academy, All Rights Reserved 16

Views
Views are a logical derivation of a table from other table/tables. A View does not exist in its own right. They provide a certain amount if logical independence They allow the same data to be seen by different users in different ways In DB2 a view that is to accept a update must be derived from a single base table

Copyright 2004, Cognizant Academy, All Rights Reserved

17

Alias & Synonym


Alias
Mean another name for the table. Aliases are used basically for accessing remote tables (in distributed data processing), which add a location prefix to their names. Using aliases creates a shorter name.

Synonym
Also means another name for the table, but is private to the user who created it.

Copyright 2004, Cognizant Academy, All Rights Reserved

18

Introduction to SQL : Features


SQL or Structured Query Language is
A Powerful language that performs the functions of data manipulation(DML), data definition(DDL) and data control or data authorization(DAL/DCL). A Non procedural language - the capability to act on a set of data and the lack of need to know how to retrieve it. An SQL can perform the functions of more than a procedure. The De Facto Standard query language for RDBMS Very flexible

SQL - Features
Unlike COBOL or 4GLs, SQL is coded without data-navigational instructions. The optimal access paths are determined by the DBMS. This is advantageous because the database knows better how it has stored data than the user. What you want and not how to get it Set level processing & multiple row processing
Copyright 2004, Cognizant Academy, All Rights Reserved 19

Introduction to SQL: Tools


Query Management Facility (QMF)
It is an MVS- and VM- based query tool It allows end users to enter SQL queries to produce a variety of reports and graphs as a result of this query QMF queries can be formulated in several ways : by direct SQL stmts, by means of relational prompted query interface or by query-by-example (QBE). QBE is similar to SQL in some ways but more user friendly

SPUFI
It supports the online execution of SQL statements from a TSO terminal Used for developers to check SQL statements or view table details Spufi menu contains the input file in which the SQL statements are coded, option for default settings and editing and the output file. Enter option 8.1 on the Cognizant m/f main menu. Provide the input/output datasets.
Copyright 2004, Cognizant Academy, All Rights Reserved 20

Introduction to SQL : DDL


Data Definition Language
Create Table Syntax: CREATE TABLE <Table_name > ( Col Name Datatype,) PRIMARY KEY(Columns) FOREIGN KEY <Name> (Column) REFERENCES dbname.tablename ON DELETE (SET NULL/CASCADE) UNIQUE (Col name) (referential constraint) 1. LIKE Table name / View name 2. IN Database Tablespace Name Foreign Key references dbname.table on relation condition for delete.
Copyright 2004, Cognizant Academy, All Rights Reserved

SQL

DDL

DML

DCL

CREATE ALTER DROP

INSERT SELECT UPDATE DELETE

GRANT REVOKE

21

Introduction to SQL : DDL


Table1 references table2(target) - Table2s Primary key is the foreign key defined in Table1 The Conditions are CASCADE, RESTRICT & SET NULL (referential constraint for the foreign key definition) Inserting (or updating ) rows in the target is allowed only if there are no rows in the referencing table
Alter Table Format: ALTER : ALTER TABLE <Tablename> ADD Column Data-type [ not null with default]

Alter allows primary & Foreign key specifications to be changed It does not support changes to width or data type of a column or dropping a column
Drop Table Format: DROP : DROP TABLE <Tablename> Similar statements are there for other database objects
Copyright 2004, Cognizant Academy, All Rights Reserved 22

Introduction to SQL : DDL Rules


Some general rules for RI & Table Parameters
Avoid nulls in columns participating in Arithmetic logic or comparisons

Primary key cols cannot be nulls


Limit referential structures to no more than three levels in a direction Use DB2s inherent features rather than program coded RIs. Do not use RIs on tables built from another RI system Consider using Fieldprocs or Editprocs or Validprocs

Copyright 2004, Cognizant Academy, All Rights Reserved

23

Introduction to SQL : DCL


GRANT & REVOKE GRANT : grants the table privileges, plan & package privileges, collection privileges, database privileges, use privileges and system privileges user with a SYSADM privilege will be responsible for overall control of the system The table privileges allowed are SELECT, UPDATE, DELETE, INSERT, (both base tables & views), ALTER(Table) & (Create)INDEX(only to base tables) There are no specific DROP privilages;the table can be dropped by its owner or a SYSADM Format of GRANT : GRANT SELECT, UPDATE(NAME,NO) ON TABLE EMPL TO A, B, C(or PUBLIC); GRANT ALL ON EMPL TO PUBLIC; GRANT EXECUTE ON PLAN PLANA TO USER; A user having authority to grant privilege to another, also has the authority to grant the privilage with with the GRANT Option
Copyright 2004, Cognizant Academy, All Rights Reserved 24

Introduction to SQL : DCL


REVOKE : this stmt revokes the privileges given to a user. The user granting the privileges has the authority to REVOKE also.

It is not possible to be column specific when revoking an UPDATE


privilege REVOKE SELECT ON TABLE EMPL FROM USERA;

Copyright 2004, Cognizant Academy, All Rights Reserved

25

Queries

Copyright 2004, Cognizant Academy, All Rights Reserved

26

You might also like