354.SQLModifications

354.SQLModifications - Database Systems I SQL Modifications...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 137 Introduction SQL provides three operations that modify the instance (state) of a DB: INSERT: inserts new tuple(s), DELETE: deletes existing tuples(s), and UPDATE: updates attribute value(s)s of existing tuple(s). Individual modifications may yield an inconsistent DB state, and only a sequence of modifications ( transaction ) may lead again to a consistent state. The DBS ensures certain properties of a transaction that guarantee the consistency of the resulting DB state.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 138 Insertion INSERT INTO R (A1, . . ., An) VALUES (v1, . . ., vn); Inserts a single tuple with values vi for attributes Ai into table R. INSERT INTO Sailors (sid, sname,rating, age) VALUES (69,’mike’, 2, 20); If values are not provided for all attributes, NULL values will be inserted. Short hand if all attribute values are given: INSERT INTO Sailors VALUES (69,’mike’, 2, 20); Values need to be provided in the order of the corresponding attributes. CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 139 Insertion INSERT INTO R (A1, . . ., An) <subquery> ; Inserts a set of tuples (relation) with values for attributes Ai into table R, as specified by a subquery. INSERT INTO Sailors (sid) SELECT DISTINCT R.sid FROM Reserves R WHERE R.sid NOT IN (SELECT sid FROM Sailors); The subquery is completely evaluated before the first tuple is inserted.
Background image of page 2
140 Deletion DELETE FROM R WHERE <condition> ; Deletes the set (!) of all tuples from R which satisfy the condition of the WHERE clause. DELETE FROM Sailors // one tuple WHERE sid = 69; DELETE FROM Sailors // multiple tuples WHERE rating < 3; Cannot directly specify a tuple to be deleted as is possible for insertions. CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 141 Update UPDATE R SET <new value assignments> WHERE <condition>; Updates attributes in the specified manner for all R tuples satisfying the given condition. UPDATE
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/07/2009 for the course CS 12601 taught by Professor Kewang during the Spring '09 term at Simon Fraser.

Page1 / 11

354.SQLModifications - Database Systems I SQL Modifications...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online