354.SQLModifications

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

Info icon This 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.
Image of page 1

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

View Full Document Right 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.
Image of page 2
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 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.
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern