














































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!















































SQL Overview
Two parts of SQL
Creating Relations in SQL
Destroying and Altering Relations
Integrity Constraints (ICs)
Student table 10 sid name login age gpa 50000 Dave dave@cs 19 3. 53666 Jones jones@cs 18 3. 53688 Smith smith@ee 18 3. 53650 Smith smith@math 19 3. 53831 Madayan madayan@music 11 1. 53832 Guldu guldu@music 12 2.
Specifying Key Constraints in SQL 11 CREATE TABLE Student (sid CHAR(20), name CHAR(20), login CHAR(10), age INTEGER, gpa REAL, UNIQUE (name, age), PRIMARY KEY (sid) )
Foreign Keys, Referential Integrity
referʼ to a tuple in another relation. (Must correspond to primary key of the second relation.) Like alogical pointerʼ.Foreign Keys in SQL
Referential Integrity in SQL
Where do ICs Come From?
Example database 19 Sailors (sid, sname, rating, age) Boats (bid, bname, color) Reserves (sid, bid, day) Key for each table indicated by underlined attributes.
20 sid bid day 22 101 10/ 22 102 10/ 22 103 10/ 22 104 10/ 31 102 11/ 31 103 11/ 31 104 11/ 64 101 9/ 64 102 9/ 74 103 9/ sid sname rating age 29 brutus 1 33 85 art 3 25. 95 bob 3 63. 96 frodo 3 25. 22 dustin 7 45 64 horatio 7 35 31 lubber 8 55. 32 andy 8 25. 74 horatio 9 35 58 rusty 10 35 71 zorba 10 16 Sailors Reserves bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red Boats