Browse Source

initial commit

master
Jared Dunbar 3 years ago
commit
fad025c876
Signed by: jared GPG Key ID: CF202CC859BAC692
  1. 132
      ZAGI.sql
  2. 87
      sql.md

132
ZAGI.sql

@ -0,0 +1,132 @@
-- create tables
CREATE TABLE vendor (
vendorid CHAR(2) NOT NULL,
vendorname VARCHAR(25) NOT NULL,
PRIMARY KEY (vendorid)
);
CREATE TABLE category (
categoryid CHAR(2) NOT NULL,
categoryname VARCHAR(25) NOT NULL,
PRIMARY KEY (categoryid)
);
CREATE TABLE product (
productid CHAR(3) NOT NULL,
productname VARCHAR(25) NOT NULL,
productprice NUMERIC (7,2) NOT NULL,
vendorid CHAR(2) NOT NULL,
categoryid CHAR(2) NOT NULL,
PRIMARY KEY (productid),
FOREIGN KEY (vendorid) REFERENCES vendor(vendorid),
FOREIGN KEY (categoryid) REFERENCES
category(categoryid)
);
CREATE TABLE region (
regionid CHAR NOT NULL,
regionname VARCHAR(25) NOT NULL,
PRIMARY KEY (regionid)
);
CREATE TABLE store (
storeid VARCHAR(3) NOT NULL,
storezip CHAR(5) NOT NULL,
regionid CHAR NOT NULL,
PRIMARY KEY (storeid),
FOREIGN KEY (regionid) REFERENCES region(regionid)
);
CREATE TABLE customer (
customerid CHAR(7) NOT NULL,
customername
VARCHAR(15) NOT NULL,
customerzip CHAR(5) NOT NULL,
PRIMARY KEY (customerid)
);
CREATE TABLE salestransaction (
tid VARCHAR(8) NOT NULL,
customerid CHAR(7) NOT NULL,
storeid VARCHAR(3) NOT NULL,
tdate DATE NOT NULL,
PRIMARY KEY (tid),
FOREIGN KEY (customerid) REFERENCES
customer(customerid),
FOREIGN KEY (storeid) REFERENCES store(storeid)
);
CREATE TABLE soldvia (
productid CHAR(3) NOT NULL,
tid VARCHAR(8) NOT NULL,
noofitems INT NOT NULL,
PRIMARY KEY (productid, tid),
FOREIGN KEY (productid) REFERENCES product(productid),
FOREIGN KEY (tid) REFERENCES salestransaction(tid)
);
-- insert data into tables
INSERT INTO vendor VALUES ('PG','Pacifica Gear');
INSERT INTO vendor VALUES ('MK','Mountain King');
INSERT INTO category VALUES ('CP','Camping');
INSERT INTO category VALUES ('FW','Footwear');
INSERT INTO product VALUES ('1X1','Zzz Bag',100,'PG','CP');
INSERT INTO product VALUES ('2X2','Easy Boot',70,'MK','FW');
INSERT INTO product VALUES ('3X3','Cosy Sock',15,'MK','FW');
INSERT INTO product VALUES ('4X4','Dura Boot',90,'PG','FW');
INSERT INTO product VALUES ('5X5','Tiny Tent',150,'MK','CP');
INSERT INTO product VALUES ('6X6','Biggy Tent',250,'MK','CP');
INSERT INTO region VALUES ('C','Chicagoland');
INSERT INTO region VALUES ('T','Tristate');
INSERT INTO store VALUES ('S1','60600','C');
INSERT INTO store VALUES ('S2','60605','C');
INSERT INTO store VALUES ('S3','35400','T');
INSERT INTO customer VALUES ('1-2-333','Tina','60137');
INSERT INTO customer VALUES ('2-3-444','Tony','60611');
INSERT INTO customer VALUES ('3-4-555','Pam ','35401');
INSERT INTO salestransaction VALUES (
'T111','1-2-333','S1','2013-01-01'
);
INSERT INTO salestransaction VALUES (
'T222','2-3-444','S2','2013-01-01'
);
INSERT INTO salestransaction VALUES (
'T333','1-2-333','S3','2013-01-02'
);
INSERT INTO salestransaction VALUES (
'T444','3-4-555','S3','2013-01-02'
);
INSERT INTO salestransaction VALUES (
'T555','2-3-444','S3','2013-01-02'
);
INSERT INTO soldvia VALUES ('1X1','T111',1);
INSERT INTO soldvia VALUES ('2X2','T222',1);
INSERT INTO soldvia VALUES ('3X3','T333',5);
INSERT INTO soldvia VALUES ('1X1','T333',1);
INSERT INTO soldvia VALUES ('4X4','T444',1);
INSERT INTO soldvia VALUES ('2X2','T444',2);
INSERT INTO soldvia VALUES ('4X4','T555',4);
INSERT INTO soldvia VALUES ('5X5','T555',2);
INSERT INTO soldvia VALUES ('6X6','T555',1);
-- delete the tables
DROP TABLE soldvia;
DROP TABLE salestransaction;
DROP TABLE store;
DROP TABLE product;
DROP TABLE vendor;
DROP TABLE region;
DROP TABLE category;
DROP TABLE customer;

87
sql.md

@ -0,0 +1,87 @@
## Create Table
```sql
CREATE TABLE `testing` (
`PID` int(11) NOT NULL,
`Name` tinytext NOT NULL,
`Position` tinytext NOT NULL,
`Pay` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```
Generically:
```sql
CREATE TABLE `<tablename>` (
`<colname>` <type> NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
```
### Example
```sql
CREATE TABLE `Employee` (
`EmpID` int(11) NOT NULL,
`EmpName` tinytext NOT NULL,
`DeptID` int(11) NOT NULL
) DEFAULT CHARSET=utf8
```
## Insert Data
```sql
INSERT INTO `Employee` (`EmpID`, `EmpName`, `DeptID`) VALUES ('1234', 'Becky', '1');
```
Generically:
```sql
INSERT INTO `<tablename>` (
`<colID`, `colID`, `<colID`
) VALUES (
'1234', 'Becky', '1'
);
```
### Example
```sql
INSERT INTO `Employee` (
`EmpID`, `EmpName`, `DeptID`
) VALUES (
'2345', 'Molly', '2'
);
INSERT INTO `Employee` (
`EmpID`, `EmpName`, `DeptID`
) VALUES (
'1324', 'Ted', '2'
);
```
EmpID | EmpName | DeptID
--- | --- | ---
1234 | Becky | 1
2345 | Molly | 2
1324 | Ted | 2
## Multiple Inserts
```sql
INSERT INTO `Employee` (`EmpID`, `EmpName`, `DeptID`) VALUES
(1234, 'Becky', 1),
(2345, 'Molly', 2),
(1324, 'Ted', 2);
COMMIT;
```
## View Table
```sql
SELECT * FROM `Employee`
```
Generically:
```sql
SELECT * FROM `<tablename>`
```
Loading…
Cancel
Save