Browse Source

initial commit

Jared Dunbar 2 years ago
commit
fad025c876
Signed by: Jared Dunbar <jrddunbr@gmail.com> GPG Key ID: CF202CC859BAC692
2 changed files with 219 additions and 0 deletions
  1. 132
    0
      ZAGI.sql
  2. 87
    0
      sql.md

+ 132
- 0
ZAGI.sql View File

@@ -0,0 +1,132 @@
1
+-- create tables
2
+
3
+CREATE TABLE vendor (
4
+  vendorid CHAR(2) NOT NULL,
5
+  vendorname VARCHAR(25) NOT NULL,
6
+  PRIMARY KEY (vendorid)
7
+);
8
+
9
+CREATE TABLE category (
10
+  categoryid CHAR(2) NOT NULL,
11
+  categoryname VARCHAR(25) NOT NULL,
12
+  PRIMARY KEY (categoryid)
13
+);
14
+
15
+CREATE TABLE product (
16
+  productid CHAR(3) NOT NULL,
17
+  productname VARCHAR(25) NOT NULL,
18
+  productprice NUMERIC (7,2) NOT NULL,
19
+  vendorid CHAR(2) NOT NULL,
20
+  categoryid CHAR(2) NOT NULL,
21
+  PRIMARY KEY (productid),
22
+  FOREIGN KEY (vendorid) REFERENCES vendor(vendorid),
23
+  FOREIGN KEY (categoryid) REFERENCES
24
+  category(categoryid)
25
+);
26
+
27
+CREATE TABLE region (
28
+  regionid CHAR NOT NULL,
29
+  regionname VARCHAR(25) NOT NULL,
30
+  PRIMARY KEY (regionid)
31
+);
32
+
33
+CREATE TABLE store (
34
+  storeid VARCHAR(3) NOT NULL,
35
+  storezip CHAR(5) NOT NULL,
36
+  regionid CHAR NOT NULL,
37
+  PRIMARY KEY (storeid),
38
+  FOREIGN KEY (regionid) REFERENCES region(regionid)
39
+);
40
+
41
+CREATE TABLE customer (
42
+  customerid CHAR(7) NOT NULL,
43
+  customername
44
+  VARCHAR(15) NOT NULL,
45
+  customerzip CHAR(5) NOT NULL,
46
+  PRIMARY KEY (customerid)
47
+);
48
+
49
+CREATE TABLE salestransaction (
50
+  tid VARCHAR(8) NOT NULL,
51
+  customerid CHAR(7) NOT NULL,
52
+  storeid VARCHAR(3) NOT NULL,
53
+  tdate DATE NOT NULL,
54
+  PRIMARY KEY (tid),
55
+  FOREIGN KEY (customerid) REFERENCES
56
+  customer(customerid),
57
+  FOREIGN KEY (storeid) REFERENCES store(storeid)
58
+);
59
+
60
+CREATE TABLE soldvia (
61
+  productid CHAR(3) NOT NULL,
62
+  tid VARCHAR(8) NOT NULL,
63
+  noofitems INT NOT NULL,
64
+  PRIMARY KEY (productid, tid),
65
+  FOREIGN KEY (productid) REFERENCES product(productid),
66
+  FOREIGN KEY (tid) REFERENCES salestransaction(tid)
67
+);
68
+
69
+
70
+-- insert data into tables
71
+
72
+INSERT INTO vendor  VALUES ('PG','Pacifica Gear');
73
+INSERT INTO vendor  VALUES ('MK','Mountain King');
74
+
75
+INSERT INTO category VALUES ('CP','Camping');
76
+INSERT INTO category VALUES ('FW','Footwear');
77
+
78
+INSERT INTO product  VALUES ('1X1','Zzz Bag',100,'PG','CP');
79
+INSERT INTO product  VALUES ('2X2','Easy Boot',70,'MK','FW');
80
+INSERT INTO product  VALUES ('3X3','Cosy Sock',15,'MK','FW');
81
+INSERT INTO product  VALUES ('4X4','Dura Boot',90,'PG','FW');
82
+INSERT INTO product  VALUES ('5X5','Tiny Tent',150,'MK','CP');
83
+INSERT INTO product VALUES ('6X6','Biggy Tent',250,'MK','CP');
84
+
85
+INSERT INTO region  VALUES ('C','Chicagoland');
86
+INSERT INTO region  VALUES ('T','Tristate');
87
+
88
+INSERT INTO store   VALUES ('S1','60600','C');
89
+INSERT INTO store   VALUES ('S2','60605','C');
90
+INSERT INTO store   VALUES ('S3','35400','T');
91
+
92
+INSERT INTO customer VALUES ('1-2-333','Tina','60137');
93
+INSERT INTO customer VALUES ('2-3-444','Tony','60611');
94
+INSERT INTO customer VALUES ('3-4-555','Pam    ','35401');
95
+
96
+INSERT INTO salestransaction VALUES (
97
+  'T111','1-2-333','S1','2013-01-01'
98
+);
99
+INSERT INTO salestransaction VALUES (
100
+  'T222','2-3-444','S2','2013-01-01'
101
+);
102
+INSERT INTO salestransaction VALUES (
103
+  'T333','1-2-333','S3','2013-01-02'
104
+);
105
+INSERT INTO salestransaction VALUES (
106
+  'T444','3-4-555','S3','2013-01-02'
107
+);
108
+INSERT INTO salestransaction VALUES (
109
+  'T555','2-3-444','S3','2013-01-02'
110
+);
111
+
112
+INSERT INTO soldvia  VALUES ('1X1','T111',1);
113
+INSERT INTO soldvia  VALUES ('2X2','T222',1);
114
+INSERT INTO soldvia  VALUES ('3X3','T333',5);
115
+INSERT INTO soldvia  VALUES ('1X1','T333',1);
116
+INSERT INTO soldvia  VALUES ('4X4','T444',1);
117
+INSERT INTO soldvia  VALUES ('2X2','T444',2);
118
+INSERT INTO soldvia  VALUES ('4X4','T555',4);
119
+INSERT INTO soldvia  VALUES ('5X5','T555',2);
120
+INSERT INTO soldvia  VALUES ('6X6','T555',1);
121
+
122
+
123
+-- delete the tables
124
+
125
+DROP TABLE soldvia;
126
+DROP TABLE salestransaction;
127
+DROP TABLE store;
128
+DROP TABLE product;
129
+DROP TABLE vendor;
130
+DROP TABLE region;
131
+DROP TABLE category;
132
+DROP TABLE customer;

+ 87
- 0
sql.md View File

@@ -0,0 +1,87 @@
1
+## Create Table
2
+
3
+```sql
4
+CREATE TABLE `testing` (
5
+  `PID` int(11) NOT NULL,
6
+  `Name` tinytext NOT NULL,
7
+  `Position` tinytext NOT NULL,
8
+  `Pay` double NOT NULL
9
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
10
+```
11
+
12
+Generically:
13
+
14
+```sql
15
+CREATE TABLE `<tablename>` (
16
+  `<colname>` <type> NOT NULL
17
+  ) ENGINE=InnoDB DEFAULT CHARSET=utf8
18
+```
19
+
20
+### Example
21
+
22
+```sql
23
+CREATE TABLE `Employee` (
24
+  `EmpID` int(11) NOT NULL,
25
+  `EmpName` tinytext NOT NULL,
26
+  `DeptID` int(11) NOT NULL
27
+) DEFAULT CHARSET=utf8
28
+```
29
+
30
+## Insert Data
31
+
32
+```sql
33
+INSERT INTO `Employee` (`EmpID`, `EmpName`, `DeptID`) VALUES ('1234', 'Becky', '1');
34
+```
35
+
36
+Generically:
37
+
38
+```sql
39
+INSERT INTO `<tablename>` (
40
+  `<colID`, `colID`, `<colID`
41
+) VALUES (
42
+  '1234', 'Becky', '1'
43
+);
44
+```
45
+
46
+### Example
47
+
48
+```sql
49
+INSERT INTO `Employee` (
50
+  `EmpID`, `EmpName`, `DeptID`
51
+) VALUES (
52
+  '2345', 'Molly', '2'
53
+);
54
+INSERT INTO `Employee` (
55
+  `EmpID`, `EmpName`, `DeptID`
56
+) VALUES (
57
+  '1324', 'Ted', '2'
58
+);
59
+```
60
+
61
+EmpID | EmpName | DeptID
62
+--- | --- | ---
63
+1234 | Becky | 1
64
+2345 | Molly | 2
65
+1324 | Ted   | 2
66
+
67
+## Multiple Inserts
68
+
69
+```sql
70
+INSERT INTO `Employee` (`EmpID`, `EmpName`, `DeptID`) VALUES
71
+(1234, 'Becky', 1),
72
+(2345, 'Molly', 2),
73
+(1324, 'Ted', 2);
74
+COMMIT;
75
+```
76
+
77
+## View Table
78
+
79
+```sql
80
+SELECT * FROM `Employee`
81
+```
82
+
83
+Generically:
84
+
85
+```sql
86
+SELECT * FROM `<tablename>`
87
+```

Loading…
Cancel
Save