Browse Source

done for class today

Jared Dunbar 2 years ago
parent
commit
cfaac3173a
Signed by: Jared Dunbar <jrddunbr@gmail.com> GPG Key ID: CF202CC859BAC692
1 changed files with 49 additions and 0 deletions
  1. 49
    0
      11-26-18.sql

+ 49
- 0
11-26-18.sql View File

@@ -0,0 +1,49 @@
1
+UPDATE manager
2
+SET mresbuilding = 'B4'
3
+WHERE managerid = 'M34';
4
+
5
+-- dropping constraints is a good way to keep data but remove the foreign keys,
6
+-- typically constraints are done if the database is expected to be modified in the future.
7
+
8
+
9
+SELECT a.buildingid, a.aptno, c.ccname
10
+FROM apartment a
11
+LEFT OUTER JOIN corpclient c
12
+ON a.ccid = c.ccid;
13
+
14
+
15
+SELECT a.buildingid, a.aptno, c.ccname
16
+FROM apartment a
17
+RIGHT OUTER JOIN corpclient c
18
+ON a.ccid = c.ccid;
19
+
20
+-- a good diagram.
21
+-- https://i.stack.imgur.com/1UKp7.png
22
+-- BTW, FULL_OUTERMOST_JOIN is not in MySQL. Use a union of left and right outer joins.
23
+
24
+-- UNION eliminates duplicates
25
+
26
+-- JOIN doesn't actually require foreign keys. It just requires matched types
27
+-- FK's exist rather for you to keep your data organized and enforce integrity
28
+
29
+-- see q44 (we've modified it to have s.smembername, below)
30
+
31
+SELECT m.managerid, m.fname, m.mlname, s.smemberid, s.smembername
32
+FROM manager m, staffmember s
33
+WHERE m.mfname = s.smembername;
34
+
35
+-- q45. IS NULL
36
+
37
+SELECT *
38
+FROM manager
39
+WHERE mbonus IS NULL;
40
+
41
+-- Good for optional queries
42
+
43
+-- q46 EXISTS
44
+-- meh according to prof. Doesn't like it, always a better way
45
+
46
+-- IS NOT NULL (replaced q47)
47
+SELECT *
48
+FROM manager
49
+WHERE mbonus IS NOT NULL;

Loading…
Cancel
Save