bd05/06 chapter 1: introduction purpose of database systems data abstraction levels data models ...

23
BD05/06 BD05/06 Chapter 1: Introduction Chapter 1: Introduction Purpose of database systems Purpose of database systems Data abstraction levels Data abstraction levels Data models Data models SQL :Data Definition Language and SQL :Data Definition Language and Data Manipulation Language Data Manipulation Language Transaction management Transaction management Database users Database users DBMS structure DBMS structure Typical database architectures Typical database architectures

Post on 19-Dec-2015

261 views

Category:

Documents


0 download

TRANSCRIPT

BD05/06BD05/06

Chapter 1: IntroductionChapter 1: Introduction Purpose of database systemsPurpose of database systems Data abstraction levelsData abstraction levels Data models Data models SQL :Data Definition Language and Data SQL :Data Definition Language and Data

Manipulation LanguageManipulation Language Transaction management Transaction management Database usersDatabase users DBMS structureDBMS structure Typical database architecturesTypical database architectures

BD05/06BD05/06

Database management systems Database management systems (DBMS)(DBMS)

Collection of Collection of interrelated datainterrelated data and a and a set of programsset of programs to access to access the data the data

DBMS contains DBMS contains relevant information about a particular information about a particular enterpriseenterprise

DBMS provides an environment that is both DBMS provides an environment that is both convenientconvenient and and efficientefficient to use. to use.

Database applications:Database applications:• Banking: all transactionsBanking: all transactions• Airlines: reservations, schedulesAirlines: reservations, schedules• Universities: registration, gradesUniversities: registration, grades• Sales: customers, products, purchasesSales: customers, products, purchases• Manufacturing: production, inventory, orders, supply chainManufacturing: production, inventory, orders, supply chain• Human resources: employee records, salaries, tax deductionsHuman resources: employee records, salaries, tax deductions

BD05/06BD05/06

DBMS vs File Systems (1)DBMS vs File Systems (1) In the early days, database applications were In the early days, database applications were

built on top of file systemsbuilt on top of file systems Drawbacks of using file systems to store data:Drawbacks of using file systems to store data:

Data redundancy and inconsistency: Data redundancy and inconsistency: Multiple file Multiple file formats, duplication of information in different filesformats, duplication of information in different files

Difficulty in accessing dataDifficulty in accessing data: Need to write a new : Need to write a new program to carry out each new taskprogram to carry out each new task

Data isolationData isolation: Multiple files and formats: Multiple files and formats Integrity problems: Integrity problems: Integrity constraints (e.g. Integrity constraints (e.g.

account balance > 0) become part of program code; account balance > 0) become part of program code; Hard to add new constraints or change existing onesHard to add new constraints or change existing ones

BD05/06BD05/06

DBMS vs File Systems (2)DBMS vs File Systems (2) Drawbacks of using file systems (cont.) Drawbacks of using file systems (cont.)

Atomicity of updatesAtomicity of updates• Failures may leave database in an inconsistent state with Failures may leave database in an inconsistent state with

partial updates carried outpartial updates carried out E.g. transfer of funds from one account to another should either E.g. transfer of funds from one account to another should either

complete or not happen at allcomplete or not happen at all

Concurrent access by multiple usersConcurrent access by multiple users• Concurrent access needed for performanceConcurrent access needed for performance• Uncontrolled concurrent accesses can lead to Uncontrolled concurrent accesses can lead to

inconsistenciesinconsistencies E.g. two people reading a balance and updating it at the same timeE.g. two people reading a balance and updating it at the same time

Security problemsSecurity problems

……. DBMS. DBMS offer solutions to all the above problems! offer solutions to all the above problems!

BD05/06BD05/06

Why use a DBMS?Why use a DBMS? DataData independence independence and and efficient efficient accessaccess

ReducedReduced application development time. application development time.

Data Data integrityintegrity and and securitysecurity..

UniformUniform data administration. data administration.

ConcurrentConcurrent access, access, recoveryrecovery from crashes. from crashes.

BD05/06BD05/06

Levels of data abstraction (1)Levels of data abstraction (1)

Physical levelPhysical level: describes how data are : describes how data are stored.stored.

Logical levelLogical level: describes data stored in the : describes data stored in the database, and the relationships among the database, and the relationships among the data.data.

View levelView level: application programs hide details : application programs hide details of data types. Views can also hide of data types. Views can also hide information (e.g., salary) for security information (e.g., salary) for security purposes. purposes.

BD05/06BD05/06

Levels of data abstraction (2)Levels of data abstraction (2)

BD05/06BD05/06

Data ModelsData Models A collection of A collection of conceptual toolsconceptual tools for describing: for describing:

data data data relationshipsdata relationships data semanticsdata semantics data constraintsdata constraints

Ex:Ex: Entity-Relationship model, UML class diagramEntity-Relationship model, UML class diagram Relational modelRelational model Other models: Other models:

• semi-structured data models (XML used to represent sstr. data)semi-structured data models (XML used to represent sstr. data)• older models: network model and hierarchical modelolder models: network model and hierarchical model

BD05/06BD05/06

Entity-Relationship ModelEntity-Relationship Model

Example of schema in the entity-relationship modelExample of schema in the entity-relationship model

BD05/06BD05/06

A Sample Relational DatabaseA Sample Relational Database

BD05/06BD05/06

Data Independence Data Independence

Applications insulated from how data is Applications insulated from how data is structured and stored.structured and stored.

Logical data independence: Protection from Protection from changes in the changes in the logical structure of data.structure of data.

CustomerPublic(customer-id, customer-name)CustomerPublic(customer-id, customer-name)

CustomerPrivate(customer-id, salary)CustomerPrivate(customer-id, salary)

Physical data independence: Protection from Protection from changes in the physical structure of data.changes in the physical structure of data.

One of the most important benefits of using a DBMS!

BD05/06BD05/06

Instances and Schemas Instances and Schemas Schema: : the logical structure of the database, the logical structure of the database, a a

description of a particular collection of data, using description of a particular collection of data, using a given data modela given data model Analogous to type information of a variable in a Analogous to type information of a variable in a

programprogram Physical schema: database design at the physical level: database design at the physical level Logical schema: database design at the logical level: database design at the logical level

Instance: : the actual content of the database at a the actual content of the database at a particular point in time particular point in time Analogous to the value of a variableAnalogous to the value of a variable

BD05/06BD05/06

Levels of data abstraction (recap)Levels of data abstraction (recap)

BD05/06BD05/06

ExampleExample

External schema (View): (View): CustomerPublic (customer-id, customer-name)CustomerPublic (customer-id, customer-name)

Logical schema: : Customer(customer-id, customer-name, customer-street, customer-age)Customer(customer-id, customer-name, customer-street, customer-age)

Account(account-number, balance) Account(account-number, balance)

Depositor(account-number, customer-id)Depositor(account-number, customer-id)

Physical schema:: Relations stored as unordered files. Relations stored as unordered files. Index on first column of Customer.Index on first column of Customer.

BD05/06BD05/06

SQL: Structured Query LanguageSQL: Structured Query Language A DBMS provides:A DBMS provides:

a a Data Definition LanguageData Definition Language (DDL) (DDL) a a Data Manipulation LanguageData Manipulation Language (DML) (DML)

as part of a single DB language: as part of a single DB language: SQLSQL

Most widely used Most widely used declarativedeclarative query language query language• ProceduralProcedural – user specifies what data is required and how to get – user specifies what data is required and how to get

those data those data • DeclarativeDeclarative – user specifies what data is required without – user specifies what data is required without

specifying how to get those dataspecifying how to get those data

BD05/06BD05/06

SQL: Data Definition Language SQL: Data Definition Language (DDL)(DDL)

DDL: Specification notation for defining the database: Specification notation for defining the database• Ex: Ex:

create tablecreate table accountaccount( ( account-numberaccount-number charchar(10),(10), balancebalance integerinteger))

DDL compiler generates a set of tables stored in a DDL compiler generates a set of tables stored in a data dictionary

Data dictionary contains Data dictionary contains metadata (i.e., data about (i.e., data about data)data) Ex: Database schema, consistency constraints, Ex: Database schema, consistency constraints, access access

methodsmethods

BD05/06BD05/06

SQL: Data Manipulation SQL: Data Manipulation Language (DML)Language (DML)

Language for Language for accessing and manipulatingaccessing and manipulating data data

Ex: find the name of the customer with Ex: find the name of the customer with customer-id 192-83-7465customer-id 192-83-7465

selectselect customer.customer-namecustomer.customer-namefromfrom customercustomerwherewhere customer.customer-idcustomer.customer-id = ‘192-83- = ‘192-83-

7465’7465’

BD05/06BD05/06

Transaction ManagementTransaction Management A A transactiontransaction is a collection of operations that performs a is a collection of operations that performs a

single logical function in a database applicationsingle logical function in a database application Ex: funds transfer includes withdraw from account A and deposit into Ex: funds transfer includes withdraw from account A and deposit into

account Baccount B

Transaction management component ensures that the Transaction management component ensures that the database remains in a database remains in a consistentconsistent (correct) state despite system (correct) state despite system failures (e.g., power failures and operating system crashes) failures (e.g., power failures and operating system crashes) and transaction failures.and transaction failures.

Transactions must be Transactions must be atomicatomic, , consistentconsistent, , isolatedisolated and and durable/persistentdurable/persistent

BD05/06BD05/06

Database Users (1)Database Users (1) Users are differentiated by the way they Users are differentiated by the way they

expect to interact with the systemexpect to interact with the systemApplication programmersApplication programmers: interact with system : interact with system

through DML calls through DML calls Sophisticated usersSophisticated users: form requests in a : form requests in a

database query languagedatabase query languageNaïve/End usersNaïve/End users: invoke one of the permanent : invoke one of the permanent

application programs that have been written application programs that have been written previouslypreviously• E.g. people accessing database over the web, E.g. people accessing database over the web,

bank tellers, clerical staffbank tellers, clerical staff

BD05/06BD05/06

Database Users (2)Database Users (2) Application programmersApplication programmers Coordinates all the activities of the database Coordinates all the activities of the database

system; has a good understanding of the enterprise’s information system; has a good understanding of the enterprise’s information resources and needs. Duties include:resources and needs. Duties include:• Schema definitionSchema definition• Storage structure and access method definitionStorage structure and access method definition• Schema and physical organization modificationSchema and physical organization modification• Granting user authority to access the databaseGranting user authority to access the database• Specifying integrity constraintsSpecifying integrity constraints• Acting as liaison with usersActing as liaison with users• Monitoring performance, tuning the system and respondingMonitoring performance, tuning the system and responding

to changes in requirementsto changes in requirements

BD05/06BD05/06

Overall DBMS Structure Overall DBMS Structure

BD05/06BD05/06

Database applicationsDatabase applications

Application programs generally access Application programs generally access databases through one of:databases through one of: LanguageLanguage (C, C++, Java, etc) (C, C++, Java, etc) extensionsextensions to to

allow embedded SQLallow embedded SQL Application program interfaceApplication program interface (e.g. (e.g.

ODBC/JDBC) which allow SQL queries to be ODBC/JDBC) which allow SQL queries to be sent to a databasesent to a database

BD05/06BD05/06

Typical application architecturesTypical application architectures

Two-tier architecture: E.g. client programs using ODBC/JDBC to communicate with a databaseThree-tier architecture: E.g. web-based applications, and applications built using “middleware”