|
| 1 | +-- DELETE STATEMENT |
| 2 | +DELETE |
| 3 | + FROM Student |
| 4 | + WHERE SAT <=900; |
| 5 | + |
| 6 | +-- UPDATE statement |
| 7 | +update Student set |
| 8 | + GPA = GPA - 0.1 |
| 9 | + where MajorId = (select id from Major where Description like '%Math%'); |
| 10 | + |
| 11 | +update Student set |
| 12 | + GPA = GPA + 0.1 |
| 13 | + where majorid = (select id from Major where Description like '%Math%'); |
| 14 | + |
| 15 | +select * |
| 16 | + from Student |
| 17 | + where majorid = (select id from Major where Description like '%Math%'); |
| 18 | + |
| 19 | +-- INSERT statement |
| 20 | +INSERT Student -- primary cant be listed if sql generates it |
| 21 | + (Firstname, Lastname, StateCode, SAT, GPA, MajorId) -- SAT/MajorId can be null |
| 22 | + VALUES |
| 23 | + ('John', 'McGaughey', 'KY', '1250', '2.8', '7'), |
| 24 | + ('Justin', 'McGaughey', 'KY', '1000', '3.2', null); |
| 25 | + |
| 26 | +DELETE from Student |
| 27 | + Where Lastname like ('%McGaughey%'); |
| 28 | + |
| 29 | +select Firstname as 'First Name', Lastname as 'Last Name', StateCode as 'State', sat, gpa, Description as 'Major' |
| 30 | + from Student s |
| 31 | + join major m |
| 32 | + on s.MajorId = m.Id |
| 33 | + where Lastname like ('%McG%'); |
| 34 | + |
| 35 | +UPDATE Student set |
| 36 | + MajorId = (select id from Major where Description like ('%Education%')) |
| 37 | + where Lastname like ('%McG%'); |
| 38 | + |
| 39 | +-- Create Major Underwater Basket Weaving |
| 40 | +insert Major |
| 41 | + (Code, Description, MinSAT) |
| 42 | + VALUES |
| 43 | + ('BSKT', 'Underwater Basket Weaving', 12); |
| 44 | + |
| 45 | +Select * from Major |
| 46 | + order by Description; |
| 47 | + |
| 48 | +-- remove major Finance, put all students in Finance into the Chad Major Underwater Basket Weaving |
| 49 | +update Student set |
| 50 | + MajorId = (select id from Major where code = 'BSKT') |
| 51 | + where MajorId = (select id from Major where Description like ('%General Studies%')); |
| 52 | + |
| 53 | +-- check all students now underwater |
| 54 | +select Firstname as 'First Name', Lastname as 'Last Name', StateCode as 'State', sat, gpa, Description as 'Major' |
| 55 | + from Student s |
| 56 | + join major m |
| 57 | + on s.MajorId = m.Id |
| 58 | + WHERE s.MajorId = (select id from Major where Description like ('%Under%')); |
| 59 | + |
| 60 | +-- delete major general studies |
| 61 | +delete major |
| 62 | + where ID = (select id from Major where Description = 'General studies') |
| 63 | + |
| 64 | +select * from major; |
0 commit comments