Lecture On Data Base Management System
Lecture On Data Base Management System
Lecture On Data Base Management System
Course Goals
First course in database systems. Learning objective
Use a relational database Build a relational database
Topics
Fundamentals
ER (Entity-Relationship) Model SQL (Structured Query Language)
Query evaluation
External sorting Evaluating relational operators
Transaction management:
Concurrency control Crash recovery
Other Topics
Prerequisite
Data structure and algorithms English skill
Taught in English & Chinese If I speak English too fast, please tell me to slow down. You can ask questions in English or Chinese.
Textbook
Required textbook: Database Management Systems, Third Edition, by Ramakrishnan and Gehrke. The textbook is available from and (and perhaps other) bookstores.
Course Format
6~7 Assignments
SQL + Written assignments
Midterm Exam
Fixed date: Nov 5, 2007 (Mon) 7:00 ~ 10:00 pm Offer once only!
Final Exam
Fixed date: Jan 14, 2008 (Mon) 2:20 ~ 5:20 pm Offer once only!
Instructor: Hao
Office hour: will announce, Room 518 or by appointment Email: [email protected]
9
Means of Communications
Course homepage http://mll.csie.ntu.edu.tw/course/database_f07/index.p hp BBS
ptt.cc, under CSIE_DBMS board Post your questions on BBS. Read posted messages before posting new questions. No SPAM. TAs respond to your questions as quickly as possible.
Lecture Notes
Available on the course homepage before each lecture
Complements, not replacement of attending lecture and reading textbook.
11
12
13
14
15
Outline
Why do we need a DBMS (Database Management System)? What can a DBMS do for an application? Why study database systems? Data Models: Overview of a Relational Model Levels of Abstraction in a DBMS Sample Queries in DBMS Transaction Management Overview Structure of a DBMS
16
Why DBMS?
Suppose that you want to build an university database. It must store the following information:
Entities: Students, Professors, Classes, Classrooms Relationships: Who teaches what? Who teaches where? Who teaches whom?
17
21
Applications
Abstraction & Interface (Database language: SQL) Perform dirty work that you dont want applications to do
System (DBMS)
Data Models
A data model is a collection of concepts for describing data.
Entity-relation (ER) model Relational model (main focus of this course)
A schema is a description of data. The relational model is the most widely used data model.
A relation is basically a table with rows and columns of records. Every relation has a schema, which describes the columns, or fields.
24
Relational Model
The entire table shows an instance of the Students relation. The Students schema is the column heads
Students(Sid: String, Name: String, Login: String, age: Integer, )
sid
53666 53688 53650
name
Jones Smith Joe
age
gpa
3.4 3.2 2.5
25
View 1
View 2
View 3
Relation tables
Students (sid: string, name: string, login: string, age: integer, gpa:real) Courses (cid: string, cname:string, credits:integer) Enrolled (sid:string, cid:string, grade:string)
Relations stored as unordered files. Index on first column of Students. Course_info(cid:string, enrollment:integer) Why?
27
Physical schema:
Data Independence
Three levels of abstraction provides data independence.
Changes in one layer only affect one upper layer. E.g., applications are not affected by changes in conceptual & physical schema.
App1 View 1 App2 View 2 View 3
28
Queries in DBMS
Sample queries on university database:
What is the name of the student with student ID 123456?
Transaction Management
A transaction is an execution of a user program in a DBMS. Transaction management deals with two things:
Concurrent execution of transactions Incomplete transactions and system crashes
30
Concurrency Control
Example: two travel agents (A, B) are trying to book one remaining airline seat (two transactions), only one transaction can succeed in booking.
// num_seats is 1 Transactions A and B: if num_seats > 0, book the seat & num_seat--; // overbook!
Crash Recovery
Example: a bank transaction transfers $100 from account A to account B
A = A - $100 <system crashes> B = B + $100 // good for the bank!
Solution: use logging, meaning that all write operations are recorded in a log on a stable storage.
A = A - $100 // recorded A value (checkpoint) in a log <system crashes> // start recovery: read the log from disk //analyze, undo, & redo
34
Layered Architecture
Applications
Queries
Query Optimization and Execution Relational Operators Files and Access Methods Buffer Management
Homework
Read Chapters 1 Read Chapter 2 (except 2.7) for next lecture
36