Relational Database Management Systems
Lecture 2
Objectives
BE ABLE TO IDENTIFY: Components of a DBMS How to store data in a database Data Models Three Schema Architecture Transaction Processing
A simplified database system environment
System Catalog
Database Environment Components
Procedures and standards writes and enforces Database administrator manages Analysts Programmers End users write use Database designer Hardware System administrator
designs
DBMS utilities Application programs access DBMS
Data
Components of the DBMS environment
Data Hardware Software Machine Bridge Procedures People Human
Hardware
Single PC A single mainframe Server-client Model
Components of the DBMS environment (2)
Software
DBMS Network software Programming languages
Data
Operational data Metadata System catalogue
Components of the DBMS environment (3)
Procedures
Log on to DBMS Start & Stop DBMS
People (Jobs for you?)
Data & database administrators Database designers Application developers End-users
Storing data in a database
A database is a collection of related data
Anything that stores/organizes data is a database in some sense.
Were concerned with is organized or more precisely, structured data or metadata.
SLIIT-2007
First Year
What do we store in a Database?
Collection of data central to some enterprise Essential to operation of enterprise Historical data can guide enterprise strategy
Of interest to other enterprises
State of database mirrors state of enterprise
Database is persistent How do we store data?
Data Models
Data Model: A set of concepts to describe the structure of a database and certain constraints that the database should obey
Many forms of data models Makes data abstraction possible Hides details of physical data storage from the user
Most commercial database systems are based on relational data model
Example
Adapted from : Elmasri & Navathe 2004. Fundamentals of Database Systems,
Categories of data models
Conceptual (high-level, semantic) data models: Provide concepts that are close to the way many users perceive data. (Also called entity-based or object-based data models.) Physical (low-level, internal) data models: Provide concepts that describe details of how data is stored in the computer.
Record formats, record orderings and access paths
Target computer specialists and not typical end users
Implementation (representational) data models: Emphasizes on how the data is represented in the database or how the data structures are implemented to represent what is modeled (eg. Relational or OO models)
Database (Implementation) Models
Hierarchical Network Relational Object-oriented
Hierarchical Model
Represents a hierarchy with the whole at the root and the components forms the child nodes in turn Thus, all the components or the nodes, taken together form the whole
Hierarchical Model
Hierarchical Model Advantages
Conceptual simplicity Database security Data independence Database integrity Efficiency (more suitable for large volumes of data with 1:M relationships)
Hierarchical Model Disadvantages
Complex implementation. Requires complete knowledge of the hierarchy Difficult to manage for complex sets of data Lacks structural independence Implementation limitations: difficult to implement M: relations
Network Model
Resembles the hierarchical model with a provision for a record to have more than one parent
An owner record is equivalent to a parent, and a member record s equivalent to a child in the hierarchical model The difference is that a record can appear as a member in more than one set
Network Model
Network Model Advantages
Conceptual simplicity More elations can be handled Data independence Database integrity Data access flexibility
Network Model Disadvantages
Complexity increases with large databases and multiple relation types Difficult to make structural changes Database design and update activities require more time
Relational Model
Relational DBMS are so called because the data they can manipulate are stored as relations Relational database system devised by Codd in 1970 An attempt to devise a standard model with a sound mathematical basis Most successful database model Most use the query language SQL Examples include: Oracle, Microsoft Access, FoxPro, MySql, SQLServer etc
Relational Model
Relational database system devised by Codd in 1970 An attempt to devise a standard model with a sound mathematical basis Most successful database model Most use the query language SQL Examples include: Oracle, Microsoft Access, FoxPro, MySql, SQLServer etc
Relations
Can be represented as tables in which rows represent tuples and columns represents attributes A relation may be described by its name and the related attributes Eg (Employee (Emp_no, Emp_ name, Age, Start_date, Address. )
Relational Database Example
BRANCH relation
branchNo B005 B007 B003 street 22 Deer Rd 16 Argyll St 163 Main St city London Aberdeen Glasgow postcode SW1 4EH AB2 3SU G11 9Q
Has
STAFF relation
StaffNo SL21 SG37 SG14 Name John White Ann Beech David Ford
Work In
Position Manager Assistant Supervisor
Salary 30000 12000 18000
branchNo B005 B003 B003
Exists
Has Has
Has
Features of Relational DBMS
2-D tables (rows and columns representing records/tuples and
fields/attributes)
Dynamic links among tables
Easy and flexible to design and use
Data independence Generic manipulation language (SQL)
Storing Data in a DBMS (contd)
In relational data model, the main construct is a relation. A relation has fields that belong to it which contain the name & data type of each field A description of data in terms of a data model is called the schema.
Every relation has a schema, which describes the name of the relation, name of each attribute (field or column), and the type of each column. e.g. Students(sid: string, name: string, login: string,
age: integer, gpa: real)
First Year SLIIT-2007 28
Schemas versus Instances
Database Schema: 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. Schema Construct: A component of the schema or an object within the schema, e.g., STUDENT, COURSE. Database Instance: The actual data stored in a database at a particular moment in time. Also called database state (or occurrence).
An Instance
Name
Smith Brown StudentNumber 17 8
Class
1 2
Major
CS CS
CourseName Intro to Computer Science
CourseNumber CS 1310
CreditHouse 4
Department CS
Data Structures Discrete Mathematics
Database
CS 3320 MATH 2410
CS 3380
4 3
3
CS MATH
CS
Database Schema Vs. Database State
Database State: Refers to the content of a database at a moment in time. Initial Database State: Refers to the database when it is loaded Valid State: A state that satisfies the structure and constraints of the database.
database schema : changes very infrequently. database state updated. . : changes every time the database is
Three-Schema Architecture
Internal schema (one)
describes physical storage structures access paths, indexes used Typically uses a physical data model
Conceptual schema at the conceptual level ( one)
describes the logical structure and constraints for the whole database for a community of users Uses a conceptual or an logical data model
External schemas (many)
Many views describe how users see data Information about schemas is stored in the system catalog
Three-Schema Architecture (Contd.)
Mappings among schema levels are needed to transform requests and data. Programs refer to an external schema, and are mapped by the DBMS to the internal schema for execution data independence
Three-Schema Architecture (Contd.)
Proposed to support DBMS characteristics of:
Program-data independence. Support of multiple views of the data.
Mappings among schema levels are needed to transform requests and data. Programs refer to an external schema, and are mapped by the DBMS to the internal schema for execution.
Levels of Abstraction in a DBMS
Conceptual schema
Describes the stored data in terms of the data model of the DBMS In a relational DBMS, the conceptual schema describes all relations that are stored in the database
First Year
SLIIT-2006
35
Levels of Abstraction in a DBMS(contd)
Physical schema
Describe storage details. Summarizes how the relations described in the conceptual schema are actually stored on secondary storage devices such as disks and tapes. Decide what file organizations used to store the relations. Create indexes to speed up data retrieval operations.
First Year SLIIT-2006 36
Levels of Abstraction in a DBMS (contd.)
External schemas
Allow data access to be customized (and authorized) at the level of individual users or groups of users. Any given database has exactly one conceptual schema and one physical schema because it has just one set of stored relations, but it may have several external schemas.
First Year
SLIIT-2006
37
Data Independence
In a DBMS that fully supports data independence,
When a schema at a lower level is changed .
Only the mappings between this schema and higher-level schema(s) need to be changed. The higher-level schemas themselves are unchanged.
The application programs need not be changed since they refer to the external schemas.
Data Independence (Contd.)
Logical Data Independence: The capacity to change the conceptual schema without having to change the external schemas and their application programs. Physical Data Independence: The capacity to change the internal schema without having to change the conceptual schema.
DBMS Languages
DML DDL
DBMS Languages (Contd.)
Data Definition Language (DDL) For DBA and database designers
( to specify the conceptual schema) 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.
DBMS Languages (Contd.)
Data Manipulation Language (DML): Used to specify database retrievals and updates.
DML commands can be embedded in a generalpurpose programming language (host language), such as COBOL, C, Java or an Assembly Language. Alternatively, stand-alone DML commands can be applied directly (query language).
DBMS Languages - SQL
Structured Query Language SQL - (also pronounced SEQUEL) Used in ORACLE and other DB systems Non-procedural - i.e. Specify what you want not how to get it Used with RELATIONAL DBMS Simple to use
Example SQL Queries
select from branchNo, city branch;
Variables
File name select * from branch where branchNo = B003;
select branchNo, name from branch, staff where branch.branchNo = staff.branchNo;
Database Architectures
Centralized DBMS: combines everything into single system includingDBMS software, hardware, application programs and user interface processing software.
Basic Client-Server Architectures
Specialized Servers with Specialized functions
Clients DBMS Server
File Servers Printer Servers Web Servers E-mail Servers
Basic Client-Server Architectures
Specialized Servers with Specialized functions
Clients DBMS Server
Clients
Provide appropriate interfaces and a client-version of the system to access and utilize the server resources. Clients maybe diskless machines or PCs or Workstations with disks with only the client software installed. Connected to the servers via some form of a network. (LAN: local area network, wireless network, etc.)
DBMS Server
Provides database query and transaction services to the clients. Some times called query and transaction servers.
Classification of DBMSs
Based on the data model used:
Traditional: Relational, Network, Hierarchical. Emerging: Object-oriented, Object-relational.
Other classifications:
Single-user (typically used with micro- computers) vs. multi-user (most DBMSs). Centralized (uses a single computer with one database) vs. distributed (uses multiple computers, multiple databases)
Classification of DBMSs
Distributed Database Systems come to be known as client server based database systems because they do not support a totally distributed environment, but rather a set of database servers supporting a set of clients.
How does a DBMS do all this?
DBMS is a complex software package The major components of a DBMS are shown
First Year
SLIIT-2007
52
How does a DBMS do all this? (contd.)
Query Evaluation Module Transaction Manager Lock Manager Recovery Manager Files and Access Methods Buffer Manager Disk Space Manager Index Files Data Files System Catalogs
First Year SLIIT-2007 53
How does a DBMS do all this? (contd.)
In this course, the focus will be to use a DBMS to design and develop a database for an application domain.
This unit will not cover the components of a DBMSs.
First Year
SLIIT-2007
54
Summary
Discussed the:
Different data models Relational data model Three schema architecture