1 introduction to databases - software school of hunan university – 2006.08

49
1 Introduction to Databases - Software School of Hunan university – 2006.08

Post on 22-Dec-2015

222 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: 1 Introduction to Databases - Software School of Hunan university – 2006.08

1

Introduction to Databases

- Software School of Hunan university –

2006.08

Page 2: 1 Introduction to Databases - Software School of Hunan university – 2006.08

2

Contents

Some common uses of database systems Evolution of Data processing. Meaning of the term database , Database

Management System (DBMS). Functions of a DBMS. Database system components. DBMS Architecture. History of the development of DBMS. Advantages and disadvantages of DBMS.

Page 3: 1 Introduction to Databases - Software School of Hunan university – 2006.08

3

Database Applications Database system is the most important development in the field of

software engineering. It is now the underlying framework of the

information system, and has fundamentally changed the way that

many organizations operate. The database is now a integral part of our day-to-day life.

Examples:– Purchases from the supermarket– Booking a holiday at the travel agents – Using the local library – Using the Internet

Page 4: 1 Introduction to Databases - Software School of Hunan university – 2006.08

4

Evolution of Data Processing

Manual filing ( 存档) system. Classified and sorted. Directory for looking something up. Competitive society demands for more and more

comprehensive information.

File-based system.– Computerized Data processing

Database system.

Page 5: 1 Introduction to Databases - Software School of Hunan university – 2006.08

5

File-Based Systems

A file-based system is a set of applications that use

files to store their data, performing services for the

end users (e.g. reports).

Each program in a file-based system contains its own

code for defining, managing, accessing and

manipulating its own data in files.

Page 6: 1 Introduction to Databases - Software School of Hunan university – 2006.08

6

DreamHome - Example of File-Based Systems

Sale department: selling and renting of property

DreamhomeProperty for rent detailsProperty Number: PG21

Business Name: _____________Address: ___________________ TelNo: ____________________ OwnerNo: _________________ Contact Name: _____________ Business Type: ______________

Name: Carol Farrel Address: 6 Achray St, Grasgow G32 9Dx________ TelNo: 0141-357-7419._______ OwnerNo: C087_____________

Address: 18 Dale Road City: gloasgow Postcode: G12 Type: House Rent: 600 No. of Rooms: 5

Allocated to Branch: 163 Main St, Glasgow BranchNo: B003

Responsible Staff Ann Beech___

Owner’s Details

Page 7: 1 Introduction to Databases - Software School of Hunan university – 2006.08

7

DreamHome - Example of File-Based Systems

Each department access to their own files through

application programs specially for them. The physical structure and storage of the data files

and records are defined in the application code.

A file is simply a collection of records (记录) , which contains logically related data.

Each record contains a logically connected set of

one or more fields (字段) .

Page 8: 1 Introduction to Databases - Software School of Hunan university – 2006.08

8

PropertyForRent

PropertyNo Street City Postcode Type rooms rent OwnerNo

PA14 16 Holhead Aberdeen AB7 5SU House 6 650 C046

PL94 6 Argyll St London NW2 Flat 4 400 C087

PG4 6 Lawrence St. Glasgow G11 9QX Flat 3 350 C040

PG36 2 Manor Rd Glasgow G32 4Qx Flat 3 375 C093

PG21 18 Dale Rd Glasgow G12 House 5 600 C087

PG16 5 Novar Dr. Glasgow G12 9AX Flat 4 450 C093

PrivateOwnerOwnerNo fName lName Address TelNo

C046 Joe Keogh 2 Fergus Dr. 01224-861212

C087 Carol Farrel 6 Achray St. 0141-357-7419

C040 Tina Murphy 63 well St. 0141-943-1728

C093 Tony Shaw 12 Park Pl. 0141-225-7025

Page 9: 1 Introduction to Databases - Software School of Hunan university – 2006.08

9

Client Forms

DreamhomeClient details

Client Number: CR74

Seen By : Ann Beech Date: 24-Mar-05 Branch No: B003 Branch City: Glasgow

First Name: Mike Last Name: Richie Address: 16 Tain St. TelNo: 01475-392178. PA1G1YQ____

Preferred ProperityType: House Maximum Monthly rent: 750 General comments:: Currently living at home with parents Getting married in August

Properity Requirement Details

Page 10: 1 Introduction to Databases - Software School of Hunan university – 2006.08

10

Client

ClientNo fName lName Address TelNo PrefType MaxRent

CR76 John Kay 56 High St. 0207-774-5632 Flat 425

CR56 Aline Stewart 64 Fern Dr. 0141-848-1825 Flat 350

CR74 Mike Richie 18 Tain St. 01475-392178 Hose 750

CR62 Mary Tregar 5 Tarbot Rd. 012240196720 Flat 600

Page 11: 1 Introduction to Databases - Software School of Hunan university – 2006.08

11

Contracts Department

DreamhomeLease details

Lease Number: 10012

Rent Start Date: 1-Jun-05 Rent Finish Date: 30-Jun-06 Duration: 1 Year

Monthly Rent: 600 Payment Method: Cheque Deposit: 1200 Paid(Y or N): Y

Client No.: CR74 Full Name: Mike Ritchie Address(Prevoius): 18Tain St. PA1G 1YQ Tel No.: 01475-392178

Properity No.: PG21 Address: 18 Dale Rd. Glasgow G12

payment Details

Page 12: 1 Introduction to Databases - Software School of Hunan university – 2006.08

12

Lease( 契约)LeaseNo PropertyNo ClientNo rent Payment

method

Deposit Paid RentStart Rentfinish Duratio

n

10024 PA14 CR62 650 Visa 1300 Y 1-Jun-01 31-May-02 12

10075 PL94 CR76 400 Cash 800 N 1-Aug-01 31-Jan-02 6

10012 PG21 CR74 600 cheque 1200 Y 1-Jul-01 30-Jun-02 12

ProperityForRent

ProperityNo Street City Postcode rent

PA14 16 Holhead Aberdeen AB7 5SU 650

PL94 6 Argyll St London NW2 400

PG21 18 Dale Rd Glasgow G12 600Client

ClientNo fName lName Address TelNo

CR76 John Kay 56 High St. 0207-774-5632

CR74 Mike Richie 18 Tain St. 01475-392178

CR62 Mary Tregar 5 Tarbot Rd. 012240196720

Client

Page 13: 1 Introduction to Databases - Software School of Hunan university – 2006.08

13

File-Based Processing

Page 14: 1 Introduction to Databases - Software School of Hunan university – 2006.08

14

Limitations of File-Based Approach

Separation and isolation of data– Each program maintains its own set of data.– Users of one program may be unaware of potentially

useful data held by other programs.

Duplication of data– Same data is held by different programs.– Wasted space and potentially different values and/or

different formats for the same item.– Issues of consistency / integrity.

Data dependence– File structure is defined in the program code.

Page 15: 1 Introduction to Databases - Software School of Hunan university – 2006.08

15

Limitations of File-Based Approach

Incompatible file formats– Programs are written in different languages, and so

cannot easily access each other’s files.

Fixed Queries/Proliferation of application programs– Programs are written to satisfy particular functions.– Any new requirement needs a new program.

Page 16: 1 Introduction to Databases - Software School of Hunan university – 2006.08

16

Database Approach

Motivation:- Definition of data was embedded in application programs,

rather than being stored separately and independently.- No control over access and manipulation of data beyond

that imposed by application programs.

Database : A collection of related data for a particular organization / enterprise.

DBMS: The software for the creation and management of the database.e.g. Oracle, DB2, Microsoft Access, SQL Server.

Database application: A Program that interacts with the database during its execution.

Database system: Database + DBMS + Database applications.

Page 17: 1 Introduction to Databases - Software School of Hunan university – 2006.08

17

Data Independence and Abstraction

The major problem with developing applications based on files is

that the application is dependent on the file structure. That is,

there is no program-data independence separating the application

from the data it is manipulating.

If the data file changes, the code that accesses the file must be

changed in the application.

One of the major advantages of databases is they provide data

abstraction. Data abstraction allows the internal definition of an

object to change without affecting programs that use the object

through an external definition.

Page 18: 1 Introduction to Databases - Software School of Hunan university – 2006.08

18

Database

Shared collection of logically related data (and a description of this data), designed to meet the information needs of an organization.

System catalog(目录 ) (metadata (元数据 ) ) provides description of data to enable program–data independence.

Logically related data comprises entities(实体) , attributes(属性) , and relationships (联系) of an organization’s information.

Page 19: 1 Introduction to Databases - Software School of Hunan university – 2006.08

19

Database Management System (DBMS)

A software system that enables users to define, create,

and maintain the database and that provides controlled

access to this database. Providing efficient, convenient, and safe multi-user

storage and access to massive amounts of persistent data. Efficient - Able to handle large data sets and complex

queries Convenient - Easy to write queries to retrieve data. Safe - Protects data from system failures and hackers. Consistent, Integrity , Concurrent.

Page 20: 1 Introduction to Databases - Software School of Hunan university – 2006.08

20

Database Management System (DBMS)

Page 21: 1 Introduction to Databases - Software School of Hunan university – 2006.08

21

Database Approach - Data Definition Language

Users describe the database to the DBMS using a Data Definition Language

(DDL). The DDL allows the user to create data structures in the data model used

by the database.

The DDL defines the external view of the database. A data model is a collection of concepts that can be used to describe the

structure of a database. Examples: relational model, object-oriented.

In the relational model, data is represented as tables and fields. A relational model contains tables and fields as its model constructs. the

specification of data types, structures and any data constraints are stored in

the database.

Page 22: 1 Introduction to Databases - Software School of Hunan university – 2006.08

22

Schemas (模式) A database designer uses a DDL to define a schema for the database. The

schema is maintained and stored in the system catalog (目录) . The schema

is one type of meta-data (元数据) .

A schema (模式) is a description of the structure of the database. A schema

contains structures, names, and types of data stored. For example, the data model for Access is a relational model. A relational model contains tables and fields as its model constructs. The

following DDL creates a product table:CREATE TABLE product (

sku as VARCHAR(10) NOT NULL,

name as VARCHAR(40),

desc as VARCHAR(50),

inventory as INTEGER,

PRIMARY KEY (sku)

);

Page 23: 1 Introduction to Databases - Software School of Hunan university – 2006.08

23

System Catalog

Repository of information (metadata) describing the

data in the database. Typically stores:

– names of authorized users;– names of data items in the database;– constraints on each data item;– data items accessible by a user and the type of access.

Used by modules such as Authorization (权限) Control and Integrity (完整性) Checker.

Page 24: 1 Introduction to Databases - Software School of Hunan university – 2006.08

24

Database Approach - Data Manipulation Language

Once a database has been created in a DBMS, the users access to the data using a Data Manipulation (操作) language (DML).

The standard DML is SQL. The DML allows for the insertion, modification, retrieval, and

deletion of data. Using a DML provides data abstraction as user queries are

specified using the names of data elements and not their physical representation.

For example, in a file system storing three fields, you would have to provide the exact location of the field in the file. In a database system, you would only have to specify it by name.

Page 25: 1 Introduction to Databases - Software School of Hunan university – 2006.08

25

SQL Examples

Retrieve all products where inventory < 10 :

SELECT name, inventory FROM product WHERE inventory < 10;

Insert a new product into the database: INSERT INTO product VALUES ('12345678','Soap','Ivory Soap',100);

Delete a product from the database:

DELETE FROM product WHERE sku = '12345678';

Page 26: 1 Introduction to Databases - Software School of Hunan university – 2006.08

26

Components of DBMS Environment

Page 27: 1 Introduction to Databases - Software School of Hunan university – 2006.08

27

Components of DBMS Environment

Hardware– Computers: CPU, Primary Memory, Secondary Memory,

(Network) Software

– Operating System, – DBMS (facilities (工具) ), – Application programs.

Data– 1 ) schema (模式) (a description of data) /System

catalog (目录) .– 2 ) Data.

Page 28: 1 Introduction to Databases - Software School of Hunan university – 2006.08

28

Components of DBMS Environment

Procedures– Instructions and rules that should be applied to the

design and use of the database and DBMS.

People– Data Administrator (DA)– Database Administrator (DBA)– Database Designers (Logical and Physical)– Application Programmers– End Users (naive and sophisticated).– DBMS Designers and developer

Page 29: 1 Introduction to Databases - Software School of Hunan university – 2006.08

29

Database People Database administrator (DBA) - responsible for installing,

maintaining, and configuring the DBMS software.

Data administrator (DA) - responsible for organizational policies on

data creation, security, and planning.

Database designer - defines and implements a schema for a

database and associated applications.

1. Logical database designer - interacts with users to determine data

requirements, constraints, and business rules.– Conceptual design - independent of any data model– Logical design - design database in a particular data model (e.g.

relational)

2. Physical database designer - implements the logical design for a data

model on a DBMS. Defines indexes, security, and constraints.

Page 30: 1 Introduction to Databases - Software School of Hunan university – 2006.08

30

Database People (2)

DBMS developer - writes code for DBMS

software.

Application developer - writes applications that

access the database using the DBMS.

User - uses the database directly or through

applications.

Page 31: 1 Introduction to Databases - Software School of Hunan university – 2006.08

31

Advantages of DBMSs

1 ) data independence / Data access transparency2 ) Sharing of data 3 ) Data consistency / integrity.4 ) concurrency, backup and recovery 5 ) Security,6 ) Enforcement of standards7 ) Economy of scale,8 ) Balanced conflicting requirements :9 ) data accessibility and responsiveness

10 ) Increased maintenance, productivity11 ) Control of data redundancy12 ) More information from the same amount of data13) Provides different views, or perspectives, of the data

Page 32: 1 Introduction to Databases - Software School of Hunan university – 2006.08

32

Disadvantages of DBMSs Complexity, Size Cost of DBMS Additional hardware costs Cost of conversion Performance Higher impact of a failure

Reasons not to use a DBMS:– If data structures are simple, well defined, and not expected

to change. – If there are stringent real-time requirements.– If only single user access is needed.

Page 33: 1 Introduction to Databases - Software School of Hunan university – 2006.08

33

Functions of a DBMS

Eight services that a DBMS should provide (Codd82):

1) Data storage, retrieval, and update

2) A user-accessible catalog describing data items

3) Transaction support

4) Concurrency control services

5) Recovery services

6) Authorization (security) services

7) Support for data communication (network access)

8) Data integrity services

Page 34: 1 Introduction to Databases - Software School of Hunan university – 2006.08

34

©DBMS Architectur

e

Page 35: 1 Introduction to Databases - Software School of Hunan university – 2006.08

35

Database system Architectures There are several different database architectures:

File-server architecture - files are shared but DBMS

processing occurs at the clients (e.g. Microsoft Access)

Two-Tier client-server architecture - dedicated machine

running DBMS accessed by clients (e.g. SQL Server)

Three-Tier client-server architecture - DBMS is bottom tier,

second tier is an application server containing business logic,

top tier is clients (e.g. Web browser/BEA WebLogic/Oracle)

Page 36: 1 Introduction to Databases - Software School of Hunan university – 2006.08

36

File-Server Architecture

File-server is connected to several workstations across a network.

Database resides on file-server.

DBMS and applications run on each workstation.

Disadvantages include:- Significant network traffic.- Copy of DBMS on each

workstation.- Concurrency, recovery and

integrity control more complex.

Page 37: 1 Introduction to Databases - Software School of Hunan university – 2006.08

37

Two-Tier Client-Server Architecture

Advantages: Only one copy of DBMS software on dedicated machine. Increased performance. Reduced hardware and communication costs. Easier to maintain consistency and manage concurrency.

Page 38: 1 Introduction to Databases - Software School of Hunan university – 2006.08

38

Three-Tier Client-Server Architecture

Advantages: Reduced client administration and cost using thin web clients. Easy to scale architecture and perform load balancing.

.

Page 39: 1 Introduction to Databases - Software School of Hunan university – 2006.08

39

Three-Tier Client-Server Architecture

Transaction (事务) Processing Monitor as middle tier of

a three-tier client-server architecture. Online Transaction Processing (OLTP).

Page 40: 1 Introduction to Databases - Software School of Hunan university – 2006.08

40

Database Architecture One of the major advantages of database systems is data

abstraction (抽象) . Data abstraction is achieved by defining

different views (视图) of the data. Each view isolates higher-

level views from data representation (表示) details. The ANSI/SPARC architecture defined in 1975 consists of three

views: Internal (内部) View - The physical representation of the

database on the computer. How the data is stored. Conceptual (概念) View - The logical structure of the

database that describes what data is stored and its relationships. External View - The user's view of the database that provides

the part of the database relevant to the user.

Page 41: 1 Introduction to Databases - Software School of Hunan university – 2006.08

41

3-Schema Architecture

Page 42: 1 Introduction to Databases - Software School of Hunan university – 2006.08

42

Benefits of 3-Schema Architecture External Level: Each user can access the data, but have their own view of the data

independent of other users.Logical data independence - conceptual schema changes do not affect external views.

Conceptual (概念) Level: Single shared data representation for all applications and users which is

independent of physical data storage.Users do not have to understand physical data representation details.The DBA can change the storage structures without affecting users or applications. Physical data independence - conceptual schema not affected by physical changes such as adding indexes or distributing data.

Physical Level:Provides standard facilities for interacting with operating system for space allocation and file manipulation.

Page 43: 1 Introduction to Databases - Software School of Hunan university – 2006.08

43

Benefits of 3-Schema Architecture

Each user to have his or her own view of the database. A view is essentially some subset of the database.

Page 44: 1 Introduction to Databases - Software School of Hunan university – 2006.08

44

Views

Benefits include:– Reduce complexity;– Provide a level of security;– Provide a mechanism to customize the appearance

of the database; – Present a consistent, unchanging picture of the

structure of the database, even if the underlying

database is changed.

Page 45: 1 Introduction to Databases - Software School of Hunan university – 2006.08

45

Benefits of 3-Schema Architecture

Page 46: 1 Introduction to Databases - Software School of Hunan university – 2006.08

46

History of Database Systems First-generation

– Hierarchical (层次) and Network– 1960s, Apollo Moon-landing project, challenging for handling and

managing the vast amounts of information.

Second generation– Relationalin 1970, Edgar F. Codd. His landmark paper "A Relational Model of Data

for Large Shared Data Banks“. Simplicity, hiding implementation details. In 1981, won Turing award

1970s, IBM System R.: a Groundbreaking project. SQL standard, DB21980s, Transaction processing, In 1998, James Gray won Turing award due

to contributions to database and transaction processing research..

Third generation– Object Relational– Object-Oriented

Page 47: 1 Introduction to Databases - Software School of Hunan university – 2006.08

47

popular DBMS

Oracle

MS SQL server

IBM DB2

MS Access

SYBASE

MYSQL

……

Page 48: 1 Introduction to Databases - Software School of Hunan university – 2006.08

48

Conclusion A database is a collection of logically related data stored and

managed by a database management system (DBMS). A DBMS has advantages over traditional file-based systems

as they support data independence and provide standard implementations for data management tasks.

- Data definition and manipulation languages (DDL and DML)

- System catalog maintains database description (schema) defined using the data model.

The 3-schema architecture consists of external, conceptual, and internal schemas. Each view provides data abstraction and isolates the layer above from certain data manipulation details.

Page 49: 1 Introduction to Databases - Software School of Hunan university – 2006.08

49

Questions

Define: database, DBMS, database system Define program-data independence, Data abstraction.

and explain how it is achieved by databases but not by file systems.

Define DDL and DML. What is the difference? Explain how a schema differs from data? Draw a diagram of the 3-schema architecture and

explain what each level provides. List benefits of the architecture.

How does a schema provide data independence?