0% found this document useful (0 votes)
168 views

1chap22 and Chap 24

This document provides an overview of databases and database management systems. It defines what a database is, why databases are needed, and the purpose of a database management system. It describes the differences between data and information and explains some common database models like hierarchical, network, and relational models. The document also discusses database concepts like schemas, subschemas, tables, fields, and keys. It provides examples of how data is organized and structured in databases.

Uploaded by

Deep Kaur
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views

1chap22 and Chap 24

This document provides an overview of databases and database management systems. It defines what a database is, why databases are needed, and the purpose of a database management system. It describes the differences between data and information and explains some common database models like hierarchical, network, and relational models. The document also discusses database concepts like schemas, subschemas, tables, fields, and keys. It provides examples of how data is organized and structured in databases.

Uploaded by

Deep Kaur
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 56

Chapter 22

Organizing Data and Information

1
What is a database
A database is any organized collection of
data. Some examples of databases you
may encounter in your daily life are:
– a telephone book
– T.V. Guide
– airline reservation system
– motor vehicle registration records
– papers in your filing cabinet
– files on your computer hard drive. 
Why do we need a database?
• Keep records of our:
– Clients
– Staff
– Volunteers
• To keep a record of activities and
interventions;
• Keep sales records;
• Develop reports;
• Perform research
What is the ultimate purpose of a
database management system?

Is to transform

Data Information Knowledge Action


DATA
Data
– A necessity for almost any enterprise to
carry out its business. Consists of raw facts,
and when organized may be transformed
into information
Database
– A collection of data organized to meet users’
needs
Database management system (DBMS)
– A group of programs that manipulate the
database and provide an interface between
the database and the user of the database or
other application programs
5
Data vs. information:
What is the difference?
• What is data? • What is information?
– Data can be defined in many – Information is data that have
ways. Information science been organized and
defines data as unprocessed communicated in a coherent
information. and meaningful manner.
– Data is converted into
information, and information
is converted into knowledge.
– Knowledge; information
evaluated and organized so
that it can be used
purposefully.
DBMS
A collection of programs that enables you to store,
modify, extract information from a database. There are
many different type of DBMSs, ranging from small
systems that run on personal computers to huge
systems that run on mainframes. The following are
examples of database applications:
– computerized library systems
– automated teller machines
– flight reservation systems
– computerized parts inventory systems

7
Terminology
Database
• A collection of integrated and related files
File
• A collection of related records
Record
• A collection of related fields
Field
• A group of characters
Character
• Basic building block of information, represented
by a byte
8
Data Entities, Attributes, and
Keys
Entity
• A generalized class of people, places, or things
(objects) for which data are collected, stored, and
maintained E.g., Customer, Employee
Attribute
• A characteristic of an entity; something the entity
is identified by E.g., Customer name, Employee
name
Keys
• A field or set of fields in a record that is used to
identify the record E.g, A field or set of fields
that uniquely identifies the record
9
The Traditional Approach
• The traditional approach…
– Separate files are created and stored for each
application program

10
Drawbacks
• Data redundancy
– Duplication of data in separate files
• Lack of data integrity
– The degree to which the data in any one file is
accurate
• Program-data dependence
– A situation in which program and data organized for
one application are incompatible with programs and
data organized differently for another application

11
Database Approach
• The database approach…
– A pool of related data is shared by multiple
application programs
– Rather than having separate data files, each
application uses a collection of data that is
either joined or related in the database

12
Advantages
– Improved strategic use of corporate data
– Reduced data redundancy
– Improved data integrity
– Easier modification and updating
– Data and program independence
– Better access to data and information
– Standardization of data access
– A framework for program development
– Better overall protection of the data
– Shared data and information resources

13
Disadvantages
– Relatively high cost of purchasing and
operating a DBMS in a mainframe operating
environment
– Increased cost of specialized staff

14
Data Modeling and
Database Models (2)
• Data model
– A map or diagram of entities and their relationships
• Enterprise data modeling
– Data modeling done at the level of the entire
organization
• Entity-relationship (ER) diagrams
– A data model that uses basic graphical symbols to
show the organization of and relationships between
data

15
Hierarchical Database Model
• Hierarchical database model
– A data model in which data are organized in a
top-down, or inverted tree structure

16
Project 1

Department A Department B Department C

Employee Employee Employee Employee Employee Employee


1 2 3 4 5 6
Network Data Model
• Network data model
• An expansion of the hierarchical database model
with an owner-member relationship in which a
member may have many owners

Project 1 Project 2

Department A Department B Department C


Relational Data Model
• Relational data model
– All data elements are placed in two-
dimensional tables, called relations, that are
the logical equivalent of files
The Relational Model
• Views entities as two-dimensional tables
– Records are rows
– Attributes (fields) are columns
• Tables can be linked
• Supports one-to-many, many-to-many,
and one-to-one relationships
Data Table 1: Project Table Data Table 2: Department Table
Project Dept. Dept. Number Dept. Name Manager SSN
Description
Number Number
257 Accounting 421-55-99993
155 Payroll 257
Manufacturin
498 Widgets 632 632 765-00-3192
g
Sales 598 Marketing 098-40-1370
226 598
manager

Data Table 3: Manager Table


SSN Last Name First Name Hire Date Dept. Number

005-10-6321 Johns Francine 10-7-65 257

549-77-1001 Buckley Bill 2-17-79 650

098-40-1370 Fiske Steven 1-5-85 598


Schemas and Subschemas
• Schema
– A description of the entire database
• Subschema
– A file that contains a description of a subset of
the database and identifies which users can
perform modifications on the data items in
that subset
DBMS

Schema

Subschema Subschema Subschema


A B C

User User User User User


1 2 3 4 5
Database Table
• Each table has a primary key
– Uniquely identifies that row of the table
– Emp_Id is the primary key in this example
– Serves as an index to quickly retrieve the record
• Columns are also called fields or attributes
• Each column has a particular data type
Emp_Id First_Name Last_Name Department
001234 Ignacio Fleta Accounting
002000 Christian Martin Computer Support
Row 002122 Orville Gibson Human Resources
(Record) 003400 Ben Smith Accounting
003780 Allison Chong Computer Support

Column Field
SQL
• Structured Query Language, abbreviated
SQL
– Usually pronounced “sequel” but also “ess-cue-ell”)
– The common language of client/server database
management systems.
– Standardized – you can use a common set of SQL
statements with all SQL-compliant systems.
– Defined by E.F. Codd at IBM research in 1970.
– Based on relational algebra and predicate logic
Queries
• Queries are the information retrieval
requests you make to the database
• Your queries are all about the information
you are trying to gather
Reports
• If the query is a question...
...then the report is its answer
• Reports can be tailored to the needs of the
data-user, making the information they
extract much more useful
Data Dictionary
• Data Dictionary
– A detailed description of all data used in the
database
Data Dictionary Features
– Provide a standard definition of terms and
data elements
– Assist programmers in designing and writing
programs
– Simplify database modification
– Reduce data redundancy
– Increase data reliability
– Faster program development
– Easier modification of data and information
Data Definition Language
• Data Definition Language (DDL)
– A collection of instructions and commands
used to define and describe data and data
relationships in a specific database
Database Transactions

1. DML
2. DDL
3. DCL
Transaction starts with an execution of SQL
statements and ends with one of the following:
– COMMIT or ROLLBACK
– DDL or DCL (automatic commit)
– user exits or quits
– system crashes
31
• A cell is also called a FIELD.
• A number of such field placed in
horizontal plane is called a RECORD or a
row.
• To create a cell in which a user can store
and maintain data,the DBA requires a
minimum of three parameters by user.
• Cell name, Cell length, Cell data type.
• These parameters are passed to the DBA
via its natural language,SQL.
• Various Datatypes:
• Char(max len 255)
• Varchar(max len 2000)
• Number
• Date(dd/mm/yy)
• Long(len upto 65,535)
Choosing Column Names
• Define a column for each piece of data
• Allow plenty of space for text fields
• Avoid using spaces in column names
• For the members of an organization:
Column Name Type Remarks
Member_ID int Primary key
First_Name varchar(40)
Last_Name varchar(40)
Phone varchar(30)
Email varchar(50)
Date_Joined smalldatetime Date only, no time values
Meetings_Attended smallint
Officer Yes/No True/False values
22.4  SQL (Structured Query
Language)
SQL keyword Description
SELECT Selects (retrieves) columns from one or more tables.
FROM Specifies tables from which to get columns or delete
rows. Required in every SELECT and DELETE
statement.
WHERE Specifies criteria that determine the rows to be
retrieved.
INNER JOIN Joins rows from multiple tables to produce a single
set of rows.
GROUP BY Specifies criteria for grouping rows.
ORDER BY Specifies criteria for ordering rows.
INSERT Inserts data into a specified table.
UPDATE Updates data in a specified table.
DELETE Deletes data from a specified table.
CREATE Creates a new table.
DROP Deletes an existing table.
COUNT Returns the number of records that satisfy given
search criteria.
Fig. 22.12 SQL keywords.
22.4.1 Basic SELECT Query
• SELECT * FROM tableName
– SELECT * FROM Authors
– SELECT authorID, lastName FROM
Authors
22.4.1 Basic SELECT Query
authorID lastName authorID lastName
1 Deitel 7 Sadhu
2 Deitel 8 McPhie
3 Nieto 9 Yaeger
4 Steinbuhler 10 Zlatkina
5 Santry 11 Wiedermann
6 Lin 12 Liperi
Fig. 22.13 authorID and lastName from the Authors table.
• The create table command:
CREATE TABLE tablename
(columnname datatype(size),
columnname datatype(size));
• Eg:
CREATE TABLE client(client_no
varchar2(6),name varchar2(20),add
varchar2(30),pincode number(6),bal_due
number(10,2));
insertion
• INSERT INTO tablename
[(columnname,columnname)]
Values(expression,expression);
• INSERT INTO client
• (client_no,name,add,Pincode)
VALUES(‘c123’,’lovely’,’phagwara’,
144444);
NOTE:character expression in single quotes
Updation
• UPDATE tablename SET
columnname=expression,
columnname=expression WHERE
columnname=expression;
• UPDATE client SET
name=‘university’,add=jalandhar’
Where client_no=‘c123’;
Deletion
• DELETE FROM tablename;
• DELETE FROM client;
• DELETE FROM client WHERE
client_no=‘c123’;
Controlling Transactions
An automatic commit occurs under the
following circumstances:
– DDL statement is issued
– DCL statement is issued
– normal exit from SQL, without explicitly
issuing COMMIT or ROLLBACK
– Abnormal Termination

42
COMMIT & ROLLBACK
• INSERT, DELETE, & UPDATE data
from a database can be reversed
(ROLLBACK) or committed (COMMIT)
• Show AUTOCOMMIT
• ROLLBACK
• COMMIT
• SET AUTOCOMMIT ON

43
State of Data Before COMMIT
or ROLLBACK
• The previous state of the data can be recovered
• The current user can review the result of the
DML operation by using SELECT
• Other user cannot view the result of the DML
statements by the current user
• The affected rows are locked (other users can not
change the data within the affected rows)

44
State of the Data after COMMIT
• Data changes are made permanent in DB
• The previous state of the data is
permanently lost
• All users can view the results
• Locks are released
• All saved points are erased

45
Committing Data
UPDATE student
SET major = ‘COSC’
WHERE id = 111;

COMMIT;

46
State of the Data after ROLLBACK
• Data changes are undone
• Previous state of the data is restored
• Locks on the rows are released

• DELETE FROM student;


10,000 records are deleted
• ROLLBACK;

47
Controlling Transactions

INSERT UPDATE INSERT DELETE

Transaction
COMMIT Point A Point B
Rollback
Rollback
Rollback

Rollback
48
Roll Back Changes to a Marker
• SAVEPOINT PointA;
…………..
• SAVEPOINT PointB;
…………………..

• ROLLBACK TO PointB;
• ROLLBACK ;

49
Distributed Databases

• Distributed database…
– A database in which the actual data may be
spread across several smaller databases
connected via telecommunications devices
Data Warehouse
• Data warehouse
– A relational database management system designed
specifically to support management decision making
– Current evolution of Decision Support Systems
(DSSs)
• Data mart
– A subset of a data warehouse for small and medium-
size businesses or departments within larger
companies
Schematic
Relational
databases

Data
Hierarchical extraction
databases process

Network
Data
databases
cleanup
process
Flat files

Spreadsheets Data
End user access wharehouse

Query and
analysis
tools
Data Mining Applications
• Data mining
– The automated discovery of patterns and relationships
in a data warehouse
• Data mining applications
• Market segmentation
• Customer queries
• Fraud detection
• Direct marketing
• Market basket analysis
• Trend analysis
Object-Relational Database
Management Systems (ORDBMS)
– Object-relational database management system (ORDBMS)
• A DBMS capable of manipulating audio, video, and graphical data.
– Hypertext
• Users can search and manipulate alphanumeric data in an
unstructured way
– Hypermedia
• Allows businesses to search and manipulate multimedia forms of data
– Spatial data technology
• Use of an object-relational database to store and access data
according to the location it describes and to permit spatial queries and
analysis
THAT’S ALL

56

You might also like