sname rating age Dustin 7 45.0 29 Brutus 1 33.0 Lubber 8 55.5 32 Andy 8 25.5 58 Rusty 10 35.0 64 Horatio 7 35.0 71 Zorba 10 16.0 74 Horatio 9 35.0 85 Art 3 25.5 95 Bob 3 63.5 day 101 10/10/98 102 10/10/98 103 10/8/98 104 10/7/98 102 11/10/98 103 11/6/98 104 11/12/98 Sailors 1 2 ( Tempred, ( ( ) > )) color ' 64 day 10/10/98 11/10/98 64 9/8/98 10/7/98 11/12/98 day 101 10/10/98 102 10/10/98 103 10/8/98 104 10/7/98 102 11/10/98 103 11/6/98 104 11/12/98 3 ( Tempgreen, ( ( ) > )) color ' green' 74 day 10/8/98 11/6/98 74 9/8/98 day 101 10/10/98 102 10/10/98 103 10/8/98 104 10/7/98 102 11/10/98 103 11/6/98 104 11/12/98 4 sname (( Tempred Tempgreen ) > Sailors ) 64 74 sname rating age Dustin 7 45.0 Lubber 8 55.5 sname Dustin Lubber sname rating age Dustin 7 45.0 29 Brutus 1 33.0 Lubber 8 55.5 32 Andy 8 25.5 58 Rusty 10 35.0 64 Horatio 7 35.0 71 Zorba 10 16.0 74 Horatio 9 35.0 85 Art 3 25.5 95 Bob 3 63.5 Sailors 5 ( Temps, ()/ ( )), sname ( Temps> Sailors)... Interlake / ( ( )) bname ' Interlake' 6 1
( Temps, ()/ ( )), day 101 10/10/98 102 10/10/98 103 10/8/98 104 10/7/98 102 11/10/98 103 11/6/98 104 11/12/98 101 102 103 104 102 103 104 64 101 64 102 74 103 101 102 103 104 sname ( Temps > Sailors) sname rating age Dustin 7 45.0 29 Brutus 1 33.0 Lubber 8 55.5 32 Andy 8 25.5 58 Rusty 10 35.0 64 Horatio 7 35.0 71 Zorba 10 16.0 74 Horatio 9 35.0 85 Art 3 25.5 95 Bob 3 63.5 Sailors sname rating age Dustin 7 45.0 sname Dustin 7 8 Interlake... day 101 10/10/98 102 10/10/98 103 10/8/98 104 10/7/98 102 11/10/98 103 11/6/98 104 11/12/98 / ( ( )) bname ' Interlake' 101 102 103 104 102 103 104 64 101 64 102 74 103 64 101 102 9 Suppliers Parts Catalog sname address 14 giant tokyo 29 hawk fukuoka dragon nagoya 33 tiger osaka 95 carp hiroshima pid pname color 102 red 104 green 106 blue 109 red 95 104 70 Suppliers ID sname address Parts pid pname color pid cost 14 102 90 14 106 80 29 102 140 109 110 33 106 50 33 109 120 Catalog pidcost 10 Suppliers( integer, sname char(16), address char(20)) Catalog( integer, pid integer, cost real) Suppliers ID sname address Parts pid pname color Catalog pidcost Suppliers( integer, sname char(16), address char(20)) Catalog( integer, pid integer, cost real) address hiroshima Suppliers sname sname ( ( )) address ' hiroshima ' Suppliers (red) Parts Suppliers sname sname ( (( ( ( Parts ))) > Catalog ) > Suppliers pid color ' sname ( ( Parts > Catalog > )) color ' Suppliers (green) Parts Suppliers (( ( ( Parts ))) > Catalog ) pid color ' red' or color 'green' ) 11 12 2
Suppliers( integer, sname char(16), address char(20)) Catalog( integer, pid integer, cost real) Parts Suppliers ( R 1, ( ( ( Parts )) > Catalog )) pid color ' ( R 2, ( ( ( Parts )) > Catalog )) pid color ' green' R1 R2 PartsSuppliers ( Catalog )/ ( ( Parts )), pid pid color ' Suppliers( integer, sname char(16), address char(20)) Catalog( integer, pid integer, cost real) 29 Suppliers sname cost 100Parts pid cost 100Parts pname cost 100Parts Suppliers sname 13 14 A4 Students( integer, sname char(16), age integer) Enrolled( integer, cid integer, grade integer) Courses(cid integer, cname char(16), teacher char(16)) Students sname age Enrolled cid grade Courses cid cname teacher A4 Students( integer, sname char(16), age integer) Enrolled( integer, cid integer, grade integer) Courses(cid integer, cname char(16), teacher char(16)) age 20sname grade D sname cname teacher sname sname cname cid Data Description Language, DDL CREATE TABLE Students ( char(5), sname char(20), login char(40), age integer, gpa real) Data Manipulation Language Data Description Language SQL-99 SQL 2009/2/12-14 17 Data Manipulation Language, DML DB SELECT sname gpa WHERE = 253 DDL DML SQL DB 18 3
Students sname login age gpa 253 ueto 2.3............... 19 20 Students sname login age gpa 253 ueto 2.3............... Courses cid cname credit AM0521......... Schema Students ( char(5), name char(16), login char(32), age integer, gpa real ) Students( char(5), sname char(20), login char(40), age integer, gpa real) Courses(cid char(6), cname char(20), credits integer) 21 Students CREATE TABLE Students ( CHAR(20), name CHAR(20), login CHAR(10), age INTEGER, gpa REAL) Enrolled CREATE TABLE Enrolled ( CHAR(20), cid CHAR(20), grade CHAR(2)) cid grade CHAR(n) VARCHAR(n) INTEGER REAL 23 24 4
DROP TABLE Students ALTER TABLE Students ADD COLUMN firstyear integer null value 25 26 Students SELECT FROM WHERE > > > 53650 Smith smith@ee 19 3.8 FROM > > AND, OR, NOT SELECT name, login WHERE age = 18 name Jones Smith login jones@cs smith@ee SELECT > FROM σ π 27 28 Students Students 53650 Smith smith@ee 19 3.8 53650 Smith smith@ee 19 3.8 SELECT name, login name Jones Smith Smith SQL login jones@cs smith@ee smith@ee 29 SELECT * WHERE age=18 π 30 5
> name = ' age > 18 Students. = Enrolled. op op op =, >,, >, >=, = AND,OR,NOT name = ' ' OR name = ' ' AND age > 20 NOT (name = ' ' AND age > 20 INSERT INTO Students (, name, login, age, gpa) VALUES (53688, Smith, smith@ee, 18, 3.2) 32 INSERT INTO Students (name,, login, age, gpa) VALUES ( Smith, 53688, smith@ee, 18, 3.2) INSERT INTO Students VALUES (53688, Smith, smith@ee, 18, 3.2) INSERT INTO Students (, name) VALUES (53688, Smith ) 53688 Smith null value 33 34 DELETE WHERE name = Smith where Smith where UPDATE Students SET age = age + 1 WHERE name = Smith where 53650 Smith smith@math 20 3.8 53688 Smith smith@ee 19 3.2 where 35 36 6