0% found this document useful (0 votes)
12 views44 pages

Lecture 8-CS-Ch09

Uploaded by

Abdul Basit
Copyright
© © All Rights Reserved
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)
12 views44 pages

Lecture 8-CS-Ch09

Uploaded by

Abdul Basit
Copyright
© © All Rights Reserved
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/ 44

Chapter 9

Database Systems

© 2007 Pearson Addison-Wesley.


All rights reserved
Background

• Data stored in independent files


• Problems:
• Data redundancy
• Data inconsistency
• Lack of data integrity or standardization

© 2007 Pearson Addison-Wesley. All rights reserved 0-2


Data Integrity

• It is the maintenance of, and the assurance of the


accuracy, consistency of data over its entire
life-cycle, and is a critical aspect to the design,
implementation and usage of any system which
stores, processes, or retrieves data.

© 2007 Pearson Addison-Wesley. All rights reserved 0-3


Database

A collection of data that is multidimensional in


the sense that internal links between its entries
make the information accessible from a variety
of perspectives

© 2007 Pearson Addison-Wesley. All rights reserved 0-4


Figure 9.1 A file versus a
database organization

© 2007 Pearson Addison-Wesley. All rights reserved 0-5


Figure 9.2 The conceptual layers
of a database implementation

© 2007 Pearson Addison-Wesley. All rights reserved 0-6


Schemas

• Schema: A description of the structure of an


entire database, used by database software to
maintain the database
• Subschema: A description of only that portion
of the database pertinent to a particular user’s
needs, used to prevent sensitive data from being
accessed by unauthorized personnel

© 2007 Pearson Addison-Wesley. All rights reserved 0-7


Database Management Systems

• Database Management System (DBMS): A software


layer that manipulates a database in response to
requests from applications
• Distributed Database: A database stored on multiple
machines
– DBMS will mask this organizational detail from its users
• Data independence: The ability to change the
organization of a database without changing the
application software that uses it

© 2007 Pearson Addison-Wesley. All rights reserved 0-8


Database Management System
(DBMS)

• Consolidate data into databases that can be


accessed by different programs .
• DBMS serves as interface between users and
databases.

© 2007 Pearson Addison-Wesley. All rights reserved 0-9


The Objectives of DBMS

 Integrating Databases
 Reducing Redundancy
 Maintaining Integrity

© 2007 Pearson Addison-Wesley. All rights reserved 0-10


Functions of DBMS

Retrieving Data, Editing. Adding, deleting


Storing, Distributing Data and Organizing Data

© 2007 Pearson Addison-Wesley. All rights reserved 0-11


Reason for using databases

Required in nearly every business


Can automate tasks and Increases business efficiency
Commercial websites use databases i.e. online stores

© 2007 Pearson Addison-Wesley. All rights reserved 0-12


Types of Databases

Enterprise Database: Large multiuser database systems developed and


maintained by IT professionals.
Personal Database (PC Database): Typically reside on personal computers
and are designed to support a particular function. Microsoft Access is the most
popular
Microsoft SQL Server: Only runs on Microsoft platforms. Eight different
versions exist
MySQL: Leading DBMS for Linux * Very inexpensive *Features are needed
in business
Oracle: Most popular enterprise-level DBMS: Platform independent
DB2: Venerable IBM database .Platform independent

© 2007 Pearson Addison-Wesley. All rights reserved 0-13


Database Models

• Database model: A conceptual view of a


database
– Relational database model
– Object-oriented database model

© 2007 Pearson Addison-Wesley. All rights reserved 0-14


Object-oriented Databases

• Object-oriented Database: A database


constructed by applying the object-oriented
paradigm
– Each entity stored as a persistent object
– Relationships indicated by links between objects
– DBMS maintains inter-object links

© 2007 Pearson Addison-Wesley. All rights reserved 0-15


Relational Database Model

• Relation: A rectangular table


– Attribute: A column in the table
– Tuple: A row in the table

© 2007 Pearson Addison-Wesley. All rights reserved 0-16


Figure 9.3 A relation containing
employee information

© 2007 Pearson Addison-Wesley. All rights reserved 0-17


Figure 9.4 A relation containing
redundancy

© 2007 Pearson Addison-Wesley. All rights reserved 0-18


Relational Design

• Avoid multiple concepts within one relation


– Can lead to redundant data
– Deleting a tuple could also delete necessary but
unrelated information

© 2007 Pearson Addison-Wesley. All rights reserved 0-19


Improving a Relational Design

• Decomposition: Dividing the columns of a


relation into two or more relations, duplicating
those columns necessary to maintain
relationships
– Lossless or nonloss decomposition: A “correct”
decomposition that does not lose any information

© 2007 Pearson Addison-Wesley. All rights reserved 0-20


Figure 9.5 An employee database
consisting of three relations

© 2007 Pearson Addison-Wesley. All rights reserved 0-21


Figure 9.6 Finding the
departments in which employee
23Y34 has worked

© 2007 Pearson Addison-Wesley. All rights reserved 0-22


Figure 9.7 A relation and a
proposed decomposition

© 2007 Pearson Addison-Wesley. All rights reserved 0-23


Relational Operations

• Select: Choose rows


• Project: Choose columns
• Join: Assemble information from two or more
relations

© 2007 Pearson Addison-Wesley. All rights reserved 0-24


Figure 9.8 The SELECT
operation

© 2007 Pearson Addison-Wesley. All rights reserved 0-25


Figure 9.9 The PROJECT
operation

© 2007 Pearson Addison-Wesley. All rights reserved 0-26


Figure 9.10 The JOIN operation

© 2007 Pearson Addison-Wesley. All rights reserved 0-27


Figure 9.11 Another example of
the JOIN operation

© 2007 Pearson Addison-Wesley. All rights reserved 0-28


Figure 9.12 An application of the
JOIN operation

© 2007 Pearson Addison-Wesley. All rights reserved 0-29


Structured Query Language (SQL)

• Operations to manipulate tuples


– insert
– update
– delete
– select

© 2007 Pearson Addison-Wesley. All rights reserved 0-30


SQL Examples

• select EmplId, Dept


from ASSIGNMENT, JOB
where ASSIGNMENT.JobId = JOB.JobId
and ASSIGNMENT.TermDate = “*”

• insert into EMPLOYEE


values (‘43212’, ‘Sue A. Burt’,
’33 Fair St.’, ‘444661111’)

© 2007 Pearson Addison-Wesley. All rights reserved 0-31


SQL Examples (continued)

• delete from EMPLOYEE


where Name = ‘G. Jerry Smith’

• update EMPLOYEE
set Address = ‘1812 Napoleon Ave.’
where Name = ‘Joe E. Baker’

© 2007 Pearson Addison-Wesley. All rights reserved 0-32


In-Class Exercise (1)

• Given the relation X below


X: A B C
2 5 7
3 3 3
4 3 2
5 2 8
what value will be extracted by the following query?
TEMP  SELECT from X where B > C
RESULT  PROJECT A from TEMP
A. 2 B. 3 C. 4 D. 5

© 2007 Pearson Addison-Wesley. All rights reserved 0-33


In-Class Exercise (2)

• Given the two relations X and Y below


X: A B Y: C D
7 s t 3
2 z r 2
what value would be retrieved by executing the following SQL
statement?
select Y.C
from X, Y
where X.A < Y.D
A. s B. z C. t D. r

© 2007 Pearson Addison-Wesley. All rights reserved 0-34


Maintaining Database Integrity

• Transaction: A sequence of operations that must all


happen together
– Example: transferring money between bank accounts
• Transaction log: A non-volatile record of each
transaction’s activities, built before the transaction is
allowed to execute
– Commit point: The point at which a transaction has been
recorded in the log
– Roll-back: The process of undoing a transaction

© 2007 Pearson Addison-Wesley. All rights reserved 0-35


Maintaining database integrity
(continued)

• Simultaneous access problems


– Incorrect summary problem
– Lost update problem
• Locking = preventing others from accessing
data being used by a transaction
– Shared lock: used when reading data
– Exclusive lock: used when altering data

© 2007 Pearson Addison-Wesley. All rights reserved 0-36


Advantages of Object-oriented
Databases

• Matches design paradigm of object-oriented


applications
• Intelligence can be built into attribute handlers
• Can handle exotic data types
– Example: multimedia

© 2007 Pearson Addison-Wesley. All rights reserved 0-37


Sequential Files

• Sequential file: A file whose contents can only


be read in order
– Reader must be able to detect end-of-file (EOF)
– Data can be stored in logical records, sorted by a
key field
• Greatly increases the speed of batch updates

© 2007 Pearson Addison-Wesley. All rights reserved 0-38


Figure 9.14 The structure of a
simple employee file implemented
as a text file

© 2007 Pearson Addison-Wesley. All rights reserved 0-39


Figure 9.15 A procedure for
merging two sequential files

© 2007 Pearson Addison-Wesley. All rights reserved 0-40


Figure 9.16
Applying the merge
algorithm (Letters
are used to represent
entire records.
The particular letter
indicates the value
of the record’s
key field.)

© 2007 Pearson Addison-Wesley. All rights reserved 0-41


Indexed Files

• Index: A list of key values and the location of


their associated records

© 2007 Pearson Addison-Wesley. All rights reserved 0-42


Figure 9.17 Opening an
indexed file

© 2007 Pearson Addison-Wesley. All rights reserved 0-43


Social Impact of Database
Technology

• Problems
– Massive amounts of personal data are being collected
• Often without knowledge or meaningful consent of affected people
– Data merging produces new, more invasive information
– Errors are widely disseminated and hard to correct
• Remedies
– Existing legal remedies often difficult to apply
– Negative publicity may be more effective

© 2007 Pearson Addison-Wesley. All rights reserved 0-44

You might also like