Beruflich Dokumente
Kultur Dokumente
CS 186, Spring 2007, Lecture 2 Cow book Section 1.5, Chapter 3 Mary Roth
Administrivia
Homework 0
Due next Tuesday, Jan 23 10 p.m. Submission instructions added to homework description Class account forms here if you need them
Outline
What we learned last time
What is and what good is a DBMS anyway? Components of a DBMS
New stuff
A brief history of databases The relational data model
DB
DB
Query Optimization and Execution Relational Operators Access Methods Buffer Management Disk Space Management
2.
Graphically compose queries, look at data
3.
Embed database access in a program
4.
Embed database access in a web application
Web browser
Command line
GUI
JDBC/ODBC app
DBMS
4. Centralized administration
stored data on single server and let people specialize in managing it
5. Concurrent access
Handles multiple users efficiently and recoverably
DB
Intermission
Get up and stretch Ask a quick question Get a drink of water
Ted Codd won the Turing award in 1981 Larry Ellison became a gillionaire
So what s the big deal about the relational data model? What is the first benefit of a DBMS?
Data independence A Data Model is key to data independence
It s the link that provides an abstraction between user s view of the world and bits stored in computer
Student (sid: string, name: string, login: string, age: integer, gpa:real)
1010111101
You can think of a relation as a set of rows or tuples. (It s basically a spread sheet!)
i.e., all rows are distinct
age 18 18 19
Cardinality = 3, arity = 5 , all rows distinct Do all values in each column of a relation instance
have to be distinct?
SQL - A language for Relational DBs SQL (a.k.a. Sequel ), standard language Data Definition Language (DDL)
create, modify, delete relations specify constraints administer users, security, etc.
SQL Overview
CREATE TABLE <name> ( <field> <domain>, INSERT INTO <name> (<field names>) VALUES (<field values>) DELETE FROM <name> WHERE <condition> UPDATE <name> SET <field name> = <value> WHERE <condition> SELECT <fields> FROM <name> WHERE <condition> )
Keys
Keys are a way to associate tuples in different relations
Enrolled
sid 53666 53666 53650 53666 cid grade Carnatic101 C Reggae203 B Topology112 A History105 B
Students
sid 53666 53688 53650 name login Jones jones@cs Smith smith@eecs Smith smith@math age 18 18 19 gpa 3.4 3.2 3.8
FOREIGN Key
PRIMARY Key
Keys are the key to data independence! Big improvement over the hierarchical model
Relationships are determined by field value, not physical pointers!
CS186
IMS requires
A change to add a field for CS186 A change to Smith s record to have him point to the new field
Enrolled
sid 53666 53666 53650 53666 53688 cid grade Carnatic101 C Reggae203 B Topology112 A History105 B CS186 A
Students
sid 53666 53688 53650 name login Jones jones@cs Smith smith@eecs Smith smith@math age 18 18 19 gpa 3.4 3.2 3.8
Exercises to test your understanding Write the DDL for our bank tables.
Include primary and foreign key definitions
Write a SQL query (DML) that returns the names and account balances for all customers that have an account balance > 2500. Write a SQL query (DML) that withdraws $300 from Frodo s account.