Sunteți pe pagina 1din 29

Introduction to Database System

Dr. Marlow Hinton Department of Computer Science NCAT

Course Outline
 Data Models
 Entity-Relationship Model  Relational Model
 Physical Database Design  Indexing  Advanced Topics  Data Mining  Database Security  Project  Oracle?  ODBC / JDBC/ Pro*C  PHP

 Relational Database
 Relational Database Design

 Object-Oriented Database
 OODB

 Querying
 Relational Algebra  SQL

 Transaction Management
 Concurrency Control  Recovery System

Database System Concepts

1.2

Yaohang Li, NCAT

Introduction to Database
 Purpose of Database Systems  View of Data  Data Models  Data Definition Language  Data Manipulation Language  Transaction Management  Storage Management  Database Administrator  Database Users  Overall System Structure

Database System Concepts

1.3

Yaohang Li, NCAT

Core of Computer Science


 What is the core of computer science?
 Data

 Computation Data Generation  Networking Data Communication  Operating System Data Organization  Security Data Protection  Protocol Data Representation  Intelligence Knowledge generation from Data

Database System Concepts

1.4

Yaohang Li, NCAT

An Interesting Salary Comparison


 Salary Poll
 Year 2000 in San Jose  A C++ Programmer  68K  An Oracle DBA  82K

Database System Concepts

1.5

Yaohang Li, NCAT

A Simple Data Management Problem -- Address Lists


 Solution 1
 A blank notebook  Entries recorded in pen, in time order

 Advantages
 Cheap, simple, private, reliable, space efficient

 Disadvantages
     Hard to search, update (modify entries), share Hard to add information, e.g., email addresses Hard to extract information, e.g., Xmax card label What about integrity What about consistency

 Multiple entries are repeated  Dont lose it!

Database System Concepts

1.6

Yaohang Li, NCAT

Solution 2: A Looseleaf Notebook with n Entries Per Page

 Better:
 Can now keep entries sorted by principal key, e.g., name  Insertions, deletions, and updates can be done

 But:
 All other disadvantages of Solution 1 still apply  In particular, no easier search by other keys, e.g., phone number

Database System Concepts

1.7

Yaohang Li, NCAT

Solution 3: A Text File, Managed by a Text Editor


 Advantages
 Free format  Unlimited size  Easily copied (e.g., for backup)  Shareable (as a unit)  Substring searchable  Cleanly updatable  Powerful, programmable tools (e.g., emacs, vi)

 Solves all our problems, right?


 Well, what if our requirements grow?  These present some complications

Database System Concepts

1.8

Yaohang Li, NCAT

Complication 1: File Gets Very Large


 Problem:
 Searching gets slow and imprecise  Search for Elm Street yields Wilhelm Streeter

 Solution
 Structure data into fields  Add indexes over fields commonly searched upon

 Database concepts
 Record organization  Keys  Indexes

Database System Concepts

1.9

Yaohang Li, NCAT

Complication 2: Need to Separate Residences From Names


 Why?
    Large families, frequent moves Might forget to update addresses of some family members Want space economy, single point of update Importance of residence as separate entity: 1 Xmas card each

 Solution
 2 files, one for persons, one for residence  But how do we associate a residence with a person?  How many residences can a person have? 0? 1? Several?

 Database Concepts
 Consistency  Normalization  Foreign keys

Database System Concepts

1.10

Yaohang Li, NCAT

Complication 3: Multiple Associations of Persons and Residences


 Meaning:
 People can own, rent, manage, visit residences  May want constraints on numbers of residences per person  and vice-versa

 Examples:
 Many-many (rich folks), many-one (single family), one-many (builder), one-one (legal residence)

 Database concepts
 Relationships  Cardinality

Database System Concepts

1.11

Yaohang Li, NCAT

Complication 4: Need to Add Information For New Purposes


 Examples
 Xmas cards sent and received  Post office gives big discount for using Zip+4 addressing

 Requirements
 Adding fields  Generating summary information (labels)

 Database Concepts
 Data abstraction  Data evolution

Database System Concepts

1.12

Yaohang Li, NCAT

Complication 5: Doing Ad Hoc Analysis and Retrieval


 Example:
 Who have we sent cards to each of the past 5 years, but received 2 or fewer cards in return?

 Requires:
 Language for expressing analysis and retrieval  Implementation that performs analysis and retrieval correctly and efficiently

 Database Concepts
 Query languages  Query optimization and execution

Database System Concepts

1.13

Yaohang Li, NCAT

Complication 6: Want to Organize the Data Differently for Some Users


 Examples
 Other family members want to see names and residences together  You dont want your kids to see your business entries

 Solution
 Use stored queries as windows onto the database  Can reunite data associated across different files  Data not selected by query is not there

 Database Concepts
 Joins  Views  Security and Privacy

Database System Concepts

1.14

Yaohang Li, NCAT

Complication 7: Required Existence of Associated Data


 Examples:
 Cannot send a Xmas card to someone without an address  Names are not unique unless qualified by residence:  Jones  Jones living at 123 Elm Street

 Solutions
 Refuse to insert a name unless it is associated with an address  Refuse to delete an address if it is associated with a name  Or, tolerate multiple non-unique names

 Database Concepts
 Referential integrity  Weak entity sets

Database System Concepts

1.15

Yaohang Li, NCAT

Complication 8: Want Programmed Access to Data


 Meaning:
 Want to write a Java program to search, display, update entries  Since data is structured, dont want char level access

 Solutions:
 Use data organization to define corresponding data types  Use access library to open, retrieve, update data

 Database Concepts
 Database Schemas  API  Embedded querying

Database System Concepts

1.16

Yaohang Li, NCAT

Complication 9: Multiple Updates On All or None Basis


 Examples
 Two households merge  Requires changing residences of several persons  What if your computer crashes during updates?

 Solutions
 Present illusion that all updates are done simultaneously  Implemented by commit or rollback of entire piece of work

 Database concepts
 Transactions  Atomicity

Database System Concepts

1.17

Yaohang Li, NCAT

Complication 10: Your Computer Crashes (again)


 Will your data still be present
 Uncorrupted?  In what state, given that a transaction was in progress?

 Solution
 Make sure old data are safely accessible until latest commit

 Database Concepts
 Data durability  Recovery

Database System Concepts

1.18

Yaohang Li, NCAT

Complication 11: Two Computers in Your Household


 How can data be shared?
 Floppy? Ugh, multiple version headaches  Lets assume the database is shared somehow  What if one user is merging households, another is splitting one up simultaneously?  What are meaningful results?

 A common policy:
 Transactions are atomic  They appear to run one after the other, in some order

 Database Concepts
 Transaction isolation  Concurrency control  Transaction serializability

Database System Concepts

1.19

Yaohang Li, NCAT

Complication 12: A Home Computer and A Business Computer


 Is there one database or two?
    Want speed, reliability of local data at each site But logically, one database for maintenance and querying Data communication between them (most of the time ) Want some capability for independent operation (robustness)

 Solutions
 Personal data on the home computer  Business data on the business computer  Common logical view

 Database Concepts
 Distributed databases  Data partitioning  Data replication

Database System Concepts

1.20

Yaohang Li, NCAT

Want to Add Family Photos, Sound & Video Clips


 Those shoe boxes in the attic must go!
 Besides, you want to be able to bore your friends at a distance  Seriously, your insurance agent wants documentation in your safe deposit box

 Requirements
 Clearly, ability to capture, store and play new media  Logical integration into existing data  Querying: all photos of the green vase that just broke

 Database Concepts
 Multi-media data  Query by content

Database System Concepts

1.21

Yaohang Li, NCAT

Complication 14: Your Uncle Louie Gets the Genealogy Bug


 His grand vision:
 All family members pool their databases over the Internet  Together, all genealogy relationships can be recorded

 But
 Aunt Sarah is paranoid: will not reveal birthdates  You too: You dont want your business associates in the genealogy database  Everyone wants complete control over safety of their own data

 Database Concept
 Federated databases

Database System Concepts

1.22

Yaohang Li, NCAT

Complication 15: You Become President


 Of USA, of University, of a large organization
 Your address list grows to hundreds of thousands or more  You realize it contains useful information in the large

 Examples
 Which are top 10 zip codes on the list?  Which zip codes have addresses that are most likely to send cards to you when you send cards to them?  Which of those zip codes are in states that had less than 5% difference in Republican / Democratic presidential votes in 2000?

 Database Concept
 Data mining

Database System Concepts

1.23

Yaohang Li, NCAT

Introduction to Database
 Database Modeling
 Mapping Real Life to Computer

 Database Design
 Efficiently organize data  Search  Update

 Database Management
 Security  Performance  Availability  Scalability  Reliability

Database System Concepts

1.24

Yaohang Li, NCAT

Database and Database Management System (DBMS)


 Database
 Collection of data  Information relevant to an enterprise

 Database Management System (DBMS)


 Collection of interrelated data  Set of programs to access the data

 DBMS contains information about a particular enterprise  Goal of DBMS


 Store and retrieve database information (Usually large bodies of information)  Convenience  Efficiency  Security  Reliability

Database System Concepts

1.25

Yaohang Li, NCAT

History of Database Systems


 1950s and early 1960s
 Magnetic tapes for data storage  Sequentially read and write  Process data in a particular order

Late 1960s and 1970s


 Use of hard disks  Direct access  Network and hierarchical databases  Allow data structures such as lists and trees to be stored on disk  Relational model is created by Codd

1980s
 Commercial relational databases  DB2, Oracle, Informix, Sybase, DEC Rdb

Early 1990s
 Development of SQL  Object-oriented support


Database System Concepts

Late 1990s
 Development of Internet  Distributed Database
1.26 Yaohang Li, NCAT

Database Applications
 Database Applications:
 Banking: all transactions  Airlines: reservations, schedules  Universities: registration, grades  Sales: customers, products, purchases  Manufacturing: production, inventory, orders, supply chain  Human resources: employee records, salaries, tax deductions  Laboratory: experiment results

 Databases touch all aspects of our lives

Database System Concepts

1.27

Yaohang Li, NCAT

Purpose of Database System


 In the early days, database applications were built on top of file systems
 Information stored in operating system files  Application programs manipulate files

 Drawbacks of using file systems to store data:


 Data redundancy and inconsistency  Multiple file formats, duplication of information in different files  Difficulty in accessing data  Need to write a new program to carry out each new task  Data isolation multiple files and formats  Integrity problems  Integrity constraints (e.g. account balance > 0) become part of program code  Hard to add new constraints or change existing ones

Database System Concepts

1.28

Yaohang Li, NCAT

Purpose of Database Systems (Cont.)


 Drawbacks of using file systems (cont.)
 Atomicity of updates  Failures may leave database in an inconsistent state with partial updates carried out  E.g. transfer of funds from one account to another should either complete or not happen at all  Concurrent access by multiple users  Concurrent accessed needed for performance  Uncontrolled concurrent accesses can lead to inconsistencies  E.g. two people reading a balance and updating it at the same time  Security problems

 Database systems offer solutions to all the above problems

Database System Concepts

1.29

Yaohang Li, NCAT

S-ar putea să vă placă și