









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani 1/28/
Excerpt from
Chapter 3, “Database Management Systems” 3ed, R. Ramakrishnan and J. Gehrke
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
object-relational model
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani Example Instance of Students Relation 1/28/
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
FROM^
Students S WHERE
S.age= •To find just names and logins, replace the first line:SELECT
S.name, S.login
sid^ name
login
age gpa 53666 Jones
jones@cs
18 3.
53688 Smith
smith@ee
18 3.
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
DROP TABLE
Students
ALTER TABLE
StudentsADD COLUMN
firstYear: integer
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
Students (sid, name, login, age, gpa) VALUES
(53688, ‘Smith’, ‘smith@ee’, 18, 3.2)
DELETEFROM^ Students SWHERE
S.name = ‘Smith’
*^ Powerful variants of these commands are available; more later!
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
all possible
instances!
^ From example, we know
name^ is not a key, but the
assertion that
sid^ is a key is given to us.
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
superkey
^ If there’s >1 key for a relation, one of the keys ischosen (by DBA) to be the
primary key
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
refer’ to a tuple in another relation. (Mustcorrespond to primary key of the second relation.)Like alogical pointer’. E.g.^ sid^ Enrolled(
sid : string,
cid : string,
grade : string)
^ If all foreign key constraints are enforced,
referential
integrity
is achieved, i.e., no dangling references. ^ Can you name a data model w/o referential integrity?• Links in HTML!
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
CREATE TABLE
Enrolled (sid^ CHAR
(20), cid
CHAR(20)
, grade
PRIMARY KEY
(sid,cid), FOREIGN KEY
(sid)^ REFERENCES
Students ) sid^ name
login
age
gpa
53666 Jones
jones@cs
18
53688 Smith
smith@eecs
18
53650 Smith
smith@math
19
sid^
cid^
grade 53666 Carnatic
C 53666 Reggae
B 53650 Topology
A 53666 History
B Enrolled
Students
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
Default is
NO ACTION ( delete/update is rejected
^ CASCADE
(also delete all tuples that refer todeleted tuple) SET NULL
(sets foreign key valueof referencing tuple)
CREATE TABLE
Enrolled (sid^ CHAR
cid^ CHAR(20)
grade^ CHAR
PRIMARY KEY
(sid,cid), FOREIGN KEY
(sid) REFERENCES
Students ON DELETE CASCADEON UPDATE SET DEFAULT
USC - CSCI585 - Spring 2008 - Farnoush Banaei-Kashani
A tabular representation of data. Simple and intuitive, currently the most widely used. Integrity constraints can be specified by the DBA,based on application semantics. DBMS checks forviolations.^ ^ Two important ICs: primary and foreign keys^ ^ In addition, we
always^ have domain constraints. ^ Powerful and natural query languages exist. ^ There are rules to translate ER to relational model