a e-r model for online flower store

49
A E-R Model for Online Flower Store Product Code Descriptio n Customer ID Name address Unit price Products Receivers Product Code quantity Order Number Buyers Customer ID Credit card Name Order lines 1 M M M 1 1 Orders Order Number Order Date Occasion N description Occasion code Picture address M M 1

Upload: shyla

Post on 13-Feb-2016

687 views

Category:

Documents


0 download

DESCRIPTION

A E-R Model for Online Flower Store. Occasion code. Product Code. Description. description. Name. Unit price. Occasion. address. Picture. Products. N. Receivers. 1. M. M. 1. Customer ID. Orders. 1. Order Date. M. M. address. Order Number. Order lines. Buyers . M. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: A E-R Model for  Online Flower Store

A E-R Model for Online Flower Store

ProductCode

Description

Customer ID

Name

addressUnit price

Products Receivers

ProductCode

quantity

OrderNumber

Buyers

Customer ID

Credit card

Name

Order lines

1M

M M

1

1

Orders

Order Number

Order Date

Occasion

N

descriptionOccasion

code

Picture

address

M

M

1

Page 2: A E-R Model for  Online Flower Store

A Simplified E-R ModelProduct

CodeDescription

Receiver Name

Receiver address

Unit price

Products

ProductCode

quantity

OrderNumber

Customer

Phone Number

Credit card #

Customer Name

Order lines

1M

M

M1

Orders

Order Number

Order Date

Occasion

N

Occasion code

Picture

addressM 1

Password

Page 3: A E-R Model for  Online Flower Store

Simplified Tables PRODUCTS

Product_Code (Primary Key) Product_Name Unit_Price

USAGE Product_Code (Concatenated Key) Occasion (Concatenated Key)

CUSTOMER Customer_Name(Primary Key) Password Address Phone_Number

Page 4: A E-R Model for  Online Flower Store

Tables ORDERS

Order_Number (Primary Key) Order_Date Customer Name (Foreign Key) Receiver Name Receiver Address Credit_Card_Type Credit_Card_Num Credit_Card_Expiry

ORDERLINE Order_Number (Concatenated Key) Product_Code (Concatenated Key) Quantity

Page 5: A E-R Model for  Online Flower Store

Functional Dependence PRODUCT (3NF)

Product_Code Product Name,Unit Price USAGE (BCNF) CUSTOMER (3NF)

CustomerID Name, Address, password, phone number ORDERS (2NF)

Order Number CustomerID, Order Date, Receiver Name,… CreditCardNum CreditCardExpiry (transitive dependence)

Receiver Name Receiver Address (transitive dependence) ORDERLINE (3NF)

ProductNumber + OrderNumber Quantity

Page 6: A E-R Model for  Online Flower Store

Transaction Processing

Page 7: A E-R Model for  Online Flower Store

Transaction A transaction is a sequence of steps

that constitute some well-defined business activities

Transaction boundaries - the logical beginning and end of transactions

Commit changes for successful transactions

Reject changes for aborted transactions

Page 8: A E-R Model for  Online Flower Store

Embedded SQL SQL can be embedded in host languages :

PL/I, COBOL, etc. SQL statements are prefixed by EXEC SQL Use EXEC SQL DECLARE to define tables,

views, and cursors In SQL, use prefix “:” to reference host

variables Return feedback information through

SQLCA

Page 9: A E-R Model for  Online Flower Store

SQLCA SQLCA SQL Communication Area

SQLCODE 0 success, +100 no data found, <0 errorEXEC SQL INCLUDE SQLCA.....IF SQLCODE < 0 THEN....

Reference: C.J. Date, A Guide to DB2 , ch.10-11.

Page 10: A E-R Model for  Online Flower Store

Example of Embedded SQL

DCL GIVENS# CHAR(5) ; DCL RANK FIXED BIN(15) ;DCL CITY CHAR(15) ;EXEC SQL DECLARE S TABLE (S# CHAR(5) NOT NULL, SNAME CHAR(20), STATUS SMALLINT, CITY CHAR(15) ;EXEC SQL INCLUDE SQLCA ;GET LIST (GIVENS# ) ;EXEC SQL SELECT STATUS, CITY INTO :RANK, :CITY FROM S WHERE S# = :GIVENS# ;IF SQLCODE = 0 THEN PUT SKIP LIST (RANK, CITY);

Page 11: A E-R Model for  Online Flower Store

Example of Embedded SQL Update:

EXEC SQL UPDATE S SET STATUS = STATUS + :RAISE, WHERE CITY = ‘LONDON’ ;

Delete:EXEC SQL DELETE FROM S WHERE STATUS = NULL ;

Insert:EXEC SQL INSERT INTO S (S#, SNAM E, STATUS, CITY) VALUES(:NEWS#, :NEWSNAME, :NEWSTATUS,'LONDON’) ;

Page 12: A E-R Model for  Online Flower Store

Using Cursors for Sequential Access

Declare a cursor and use it as a sequential file of the query resultsEXEC SQL DECLARE X CURSOR FOR SELECT S#, SNAME, STATUS FROM S WHERE CITY = :PCITY FOR UPDATE OF STATUS ;GET LIST (PCITY, GIVENINC);EXEC SQL OPEN X ;DO WHILE ( SQLCODE = 0 ) EXEC SQL FETCH X INTO :PS#, :PSNAME, :PSTATUS; PUT SKIP LIST(PSNAME, PS#, PSTATUS); EXEC SQL UPDATE S SET STATUS = STATUS + :GIVENINC

WHERE CURRENT OF X END;EXEC SQL CLOSE X ;

Page 13: A E-R Model for  Online Flower Store

Integrity Control in SQL Change supplier # of supplier SX from SX to SY in

both tables S and SP.TRANEX: PROC OPTIONS (MAIN) : EXEC SQL WHENEVER SQLERROR GO TO UNDO; GET LIST(SX, SY); EXEC SQL UPDATE S SET S# = :SY WHERE S# = :SX; EXEC SQL UPDATE SP SET S# = :SY WHERE S# = :SX; EXEC SQL COMMIT; GO TO FINISH; UNDO: EXEC SQL ROLLBACK;FINISH: RETURN; END TRANEX;

Page 14: A E-R Model for  Online Flower Store

Desired Transaction Properties

Atomicity -- All operations of a transaction must be completed. If not, the transaction is aborted.

Durability -- When a transaction is completed, the database reaches a consistent state which cannot be lost.

Serializability -- The concurrent transaction are treated as though they were executed in serial order.

Isolation -- The data used during the execution of a transaction cannot be used by a second transaction until the first one is completed.

Page 15: A E-R Model for  Online Flower Store

Concurrent Transactions

When transactions are interleaved, errors will occur in updating unless the DBMS has features to prevent interference between transactions

CUSTA

BAL100

GET CUSTAA 100

GET CUSTAA 100

BAL : BAL - 50

A 50

BAL : BAL + 25

A 125

A 50

A 125

STORE CUSTA STORE CUSTA

1 2

34

Page 16: A E-R Model for  Online Flower Store

Problems with Concurrent Transactions Lost updates - T2 is executed

before T1 is committed Uncommitted data -- T1 is rolled

back after T2 accessed the uncommitted data

Inconsistent retrievals - - T1 calculates some summary data while T2 is updating the data

Page 17: A E-R Model for  Online Flower Store

Concurrency Control - the Scheduler

Establish the order in which the operations in concurrent transactions are executed without causing inconsistency

Locking Guarantee exclusive use of a data item to a current transaction

Timestamping Assign a global unique timestamp to each transaction. Execute operations in timestamp order.

Page 18: A E-R Model for  Online Flower Store

Resource Locking Lock granularity

Database level, Table level, Page level, Row level, Field level

Lock Types Binary locks -- locked ,Unlocked Shared/Exclusive Locks -- Unlocked, Shared

(Read) lock, Exclusive (Write) lock Two-Phase Locking

A growing phase A shrinking phase

Page 19: A E-R Model for  Online Flower Store

Deadlock Deadly embrace Deadlock prevention:lock all required

records at beginning of transaction Deadlock resolution:back out of one of

transactions and start againUser A

Lock X

Wait for Y

User B

Lock Y

Wait for X

X

Y

Page 20: A E-R Model for  Online Flower Store

Optimistic vs. Pessimistic Locking Optimistic locking

Assume the majority of database operations do not conflict.

Process each transaction in three phases: read, validation, and write.

Less restriction, may repeat process Pessimistic locking

Assume the conflicts most likely will happen. Lock, process, and unlock. More restriction, no repeat process

Page 21: A E-R Model for  Online Flower Store
Page 22: A E-R Model for  Online Flower Store
Page 23: A E-R Model for  Online Flower Store

Database Recovery Database may be damaged or lost because

of some system failure. The DBMS must provide mechanisms for restoring a database quickly and accurately after loss or damage.

System failures: machine failuresdisk head crashesprogram bugsincorrect operation

Page 24: A E-R Model for  Online Flower Store

Database Recovery

Database(current)

Database(backup)

Databasechange

log

Transactionlog

DBMS

before image

after image

Page 25: A E-R Model for  Online Flower Store
Page 26: A E-R Model for  Online Flower Store

Basic Recovery Facilities Backup facilities

Provide periodic backup copies of the entire database Journalizing facilities

Maintain an audit trail of transactions and database changes

Checkpoint facilityPeriodically suspends all processing and synchronizes its files and journals

Recovery managerAllows the DBMS to restore the database to a correct condition and restart processing transactions

Page 27: A E-R Model for  Online Flower Store

Recovery via Restore/Rerun Restore the latest backup copy Reprocess the day’s transactions (up to

the point of failure) against the backup copy of the database

Simple procedure Time to reprocess transactions may be

prohibitive Sequencing of reprocessed transactions

may be different from the original

Page 28: A E-R Model for  Online Flower Store

Recovery via Roll Back/Roll Forward

Database

withchanges

Beforeimages

Databasewithoutchanges

Databasewithoutchanges

Databasewith

changes

Afterimages

Undo

Redo

New Old

Old(saved) NewRoll Forward

(Repeating Database Changes)

Roll Back(Removing Database Changes)

Page 29: A E-R Model for  Online Flower Store
Page 30: A E-R Model for  Online Flower Store

Recovery Strategies Aborted transactions (i.e. communication interruption)

Backward recovery Incorrect data

Backward recovery or add compensation transactions System failure (database is not damaged)

Restart from the most recent checkpoint before the system failure, roll forward.

Database destruction (database damaged)Restore backup copy.Forward recovery to the check point before the loss occurred. Reprocess transactions after the check point.

Page 31: A E-R Model for  Online Flower Store

Security Control Security refers to the protection of

data against unauthorized disclosure, alteration, or destruction Physical security Password security Authentication schemas: biometric

devices, smart card

Page 32: A E-R Model for  Online Flower Store

Security Control Views or subschemas User-defined procedures Authorization rules Audit trails Data encryption

Page 33: A E-R Model for  Online Flower Store
Page 34: A E-R Model for  Online Flower Store

Authorization Rules Grant select on Staff to User01

Revoke update on Staff from User02

Authorization rulesSubject

Salesdepartment

Ordertransactions

Object

Customerrecord

Customerrecord

Action

Insert

Read

Constraint

Credit limit<= 5000

None

Page 35: A E-R Model for  Online Flower Store
Page 36: A E-R Model for  Online Flower Store

Database Administration A critical success factor in

managing the data resource in an organization

An indication of top management’s commitment to data resource management

Page 37: A E-R Model for  Online Flower Store

DA and DBA Data Administrator (DA)

Responsible for controlling the overall corporate data resource, both computerized and non-computerized.Strong managerial orientation with company-wide scope.

Database Administrator (DBA)Responsible for the control of the centralized and shared database.Tends to be more technically oriented and has a narrower, DBMS-specific scope.

Page 38: A E-R Model for  Online Flower Store

DBA Placement Should not be organizationally below any

group on which it imposes restrictions. Should not be more than one level above the

organizations with which it interfaces.

D B A

M anagerS ys tem s

M anagerO perations

M anagerP rogram m ing

V ice P res identD ata Process ing

Page 39: A E-R Model for  Online Flower Store

Desired DBA Skills

Broad business understanding

Coordination skills Analytical skills Conflict resolution

skills Communication skills Negotiation skills

Broad data processing background

Systems Development Life Cycle

Structured methodologies Database Life Cycle Database design and

modeling skills Data dictionary

management

Managerial

Technical

Page 40: A E-R Model for  Online Flower Store

DBA’s Managerial Role Support the end-user community, resolve conflicts Enforce policies, procedures, and standards for data

creation, usage, distribution, and deletion within the database.

Control data security, privacy, and integrityData are protected, reconstructable, auditable, tamperproof.Users are identifiable, authorized, monitored.

Plan, test, and Implement data backup and recoveryDatabase security officer (DSO), Disaster management

Ensure data be distributed to the right persons at the right time in the right format.

Page 41: A E-R Model for  Online Flower Store

DBA’s Technical Role DBMS and utilities selection, evaluation ,and installation Design and implementation of databases and

applications Testing and evaluation of databases and applications Operation of the DBMS, utilities, and applications

System support, performance monitoring and tuning, backup and recovery, security auditing and monitoring

Training and supporting users to use DBMS Maintenance of the DBMS, utilities, and applications

Storage reorganization, software upgrade, data migration and conversion

Page 42: A E-R Model for  Online Flower Store

Database Administration Tools Data Dictionary

Stores the definition of data characteristics and relationships.May be integrated or stand-alone, active or passive.A tool for information resource management.The basis for monitoring database use and the assignment of access rights to the database users.Support data analysis-and-design activities

CASE Tools

Page 43: A E-R Model for  Online Flower Store

Database Administration Tools The Data Dictionary

Different types of data dictionaries: An integrated data dictionary is included

with the DBMS, while a stand-alone data dictionary comes from a third-party vendor.

An active data dictionary is automatically updated by the DBMS, while a passive data dictionary requires a batch process to create and update the dictionary.

Page 44: A E-R Model for  Online Flower Store

Database Administration Tools CASE Tools

CASE -- Computer-Aided Software Engineering It provides an automated framework for the

Systems Development Life Cycle. Front-end CASE tools provide support for the

planning, analysis, and design phases. Back-end CASE tools provide support for the coding

and implementation phases. It is based on the use of structured

methodologies and powerful graphical interfaces.

Page 45: A E-R Model for  Online Flower Store

Database Administration Tools CASE Tools

Benefits of CASE tools A reduction in development time and costs The automation of the SDLC Standardization of the systems development

methodologies Easier maintenance of application systems

developed with CASE tools Improve communications among the DBA,

applications designers, and the end users.

Page 46: A E-R Model for  Online Flower Store

Database Administration Tools CASE Tools

A CASE tool keeps track of all objects created by the systems designer in the data dictionary.

Some CASE tools provide interfaces that interact with the DBMS.

The CASE tool integrates all systems development information in a common repository.

Page 47: A E-R Model for  Online Flower Store

Database Administration Tools Commercial CASE Tools

Excelerator from Intersolv, Inc. provides five components:

Graphics designed to produce structured diagrams as data flow diagrams and E-R diagrams.

Screen painters and report generators to produce the information system’s input/output formats.

An integrated repository for storing and cross-referencing the system design data.

An analysis segment to provide a fully automated check on system consistency, syntax, and completeness.

A program document generator.

Page 48: A E-R Model for  Online Flower Store

Database Administration Tools Commercial CASE Tools

ERwin by LogicWorks It produces fully documented E-R diagrams that

can be displayed at different abstraction levels. It is able to produce detailed relational designs.

Major relational DBMS vendors, such as ORACLE, provide fully integrated CASE tools for their own DBMS software as well as for RDBMSs supplied by other vendors.

Page 49: A E-R Model for  Online Flower Store

Future Trend The development of distributed databases

may force an organization to decentralize the data-administration function further.

The introduction of an object-oriented DBMS is very likely to add more coding in the DBA’s data modeling and design activities, thus expanding and diversifying the DBA’s job.

The rapid spread of microcomputers and local area networks tends to diffuse operational control over data, thus making centralized data administration more difficult.