-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupersightingDB.sql
More file actions
72 lines (57 loc) · 2.56 KB
/
supersightingDB.sql
File metadata and controls
72 lines (57 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
DROP DATABASE IF EXISTS supersightingDB;
CREATE DATABASE supersightingDB;
USE supersightingDB;
CREATE TABLE superpower(
superpowerId INT PRIMARY KEY AUTO_INCREMENT,
superpowerName VARCHAR(50) NOT NULL
);
CREATE TABLE hero(
heroId INT PRIMARY KEY AUTO_INCREMENT,
heroName VARCHAR(50) NOT NULL,
heroDescription VARCHAR(200),
superpowerId INT NOT NULL,
FOREIGN KEY(superpowerId) REFERENCES superpower(superpowerId)
);
CREATE TABLE location(
locationId INT PRIMARY KEY AUTO_INCREMENT,
locationName VARCHAR(50) NOT NULL,
description VARCHAR(200),
address VARCHAR(200),
longitude DOUBLE NOT NULL,
latitude DOUBLE NOT NULL
);
CREATE TABLE sighting(
sightingId INT PRIMARY KEY AUTO_INCREMENT,
sightingDate DATE NULL,
locationId INT NOT NULL,
heroId INT NOT NULL,
FOREIGN KEY(heroId) REFERENCES hero(heroId),
FOREIGN KEY(locationId) REFERENCES location(locationId)
);
CREATE TABLE organization(
organizationId INT PRIMARY KEY AUTO_INCREMENT,
organizationName VARCHAR(50) NOT NULL,
organizationDescription VARCHAR(200),
organizationAddress VARCHAR(100) NOT NULL
);
CREATE TABLE hero_organization(
heroId INT NOT NULL,
organizationId INT NOT NULL,
PRIMARY KEY(heroId, organizationId),
FOREIGN KEY(heroId) REFERENCES hero(heroId),
FOREIGN KEY(organizationId) REFERENCES organization(organizationId)
);
INSERT INTO superpower(superpowerName) VALUES('Teleport');
INSERT INTO superpower(superpowerName) VALUES('Fly');
INSERT INTO superpower(superpowerName) VALUES('Speed');
INSERT INTO hero(heroName, heroDescription, superpowerId) VALUES('Wanda', 'Vison', 1);
INSERT INTO hero(heroName, heroDescription, superpowerId) VALUES('Iron Man', 'Test', 2);
INSERT INTO organization(organizationName, organizationDescription, organizationAddress) VALUES('Blank HQ', 'Looking for hires', 'Some place anywhere');
INSERT INTO organization(organizationName, organizationDescription, organizationAddress) VALUES('Wonka Bar', 'Looking for hires', 'Test place');
INSERT INTO hero_organization(heroId, organizationId) VALUES(1, 1);
INSERT INTO hero_organization(heroId, organizationId) VALUES(2, 2);
INSERT INTO location(locationName, description, address, longitude, latitude) VALUES("Starbucks", "Some Test", "Madison Street NY", "98.3", "76.3");
INSERT INTO sighting(sightingDate, locationId, heroId) VALUES("2021-01-12", 1, 2);
INSERT INTO sighting(sightingDate, locationId, heroId) VALUES("2022-03-22", 1, 1);
-- SELECT s.* FROM hero h JOIN superpower s ON h.superpowerId = s.superpowerId WHERE h.heroId = 1;
SELECT * FROM hero_organization;