-
Notifications
You must be signed in to change notification settings - Fork 0
/
SuperSightings copy.sql
99 lines (80 loc) · 2.9 KB
/
SuperSightings copy.sql
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
DROP DATABASE IF EXISTS SuperSightings;
CREATE DATABASE SuperSightings;
USE SuperSightings;
CREATE TABLE IF NOT EXISTS `Super` (
`SuperId` int(11) not null auto_increment,
`Name` varchar(60) not null,
`Description` text(100) not null,
PRIMARY KEY(`SuperId`)
);
CREATE TABLE IF NOT EXISTS `Organization` (
`OrganizationId` int(11) not null auto_increment,
`Name` varchar(60) not null,
`Description` text(100) not null,
`Type` varchar(7) not null,
`Address` varchar(60) not null,
`City` varchar(60) not null,
`State` varchar(40) not null,
`Zipcode` varchar(11) not null,
`Phone` varchar(20) not null,
PRIMARY KEY(`OrganizationId`)
);
CREATE TABLE IF NOT EXISTS `SuperOrganization`(
`SuperId`int(11) not null,
`OrganizationId` int(11) not null,
PRIMARY KEY (`SuperId`, `OrganizationId`)
);
ALTER TABLE `SuperOrganization`
ADD CONSTRAINT `fk_SuperOrganization_Super`FOREIGN KEY (`SuperId`) REFERENCES `Super`
(`SuperId`) ON DELETE NO ACTION;
ALTER TABLE `SuperOrganization`
ADD CONSTRAINT `fk_SuperOrganization_Organization` FOREIGN KEY(`OrganizationId`) REFERENCES `Organization`
(`OrganizationId`);
CREATE TABLE IF NOT EXISTS `Location` (
`LocationId` int(11) not null auto_increment,
`Name` varchar(60) not null,
`Description` text(100) not null,
`Address` varchar(60) not null,
`City` varchar(60) not null,
`State` varchar(40) not null,
`Zipcode` varchar(11) not null,
`Longitude` decimal(9,6) not null,
`Latitude` decimal(9,6) not null,
PRIMARY KEY(`LocationId`)
);
CREATE TABLE IF NOT EXISTS `Power` (
`PowerId` int(11) not null auto_increment,
`Description` text(100) not null,
PRIMARY KEY(`PowerId`)
);
CREATE TABLE IF NOT EXISTS `SuperPower` (
`SuperId` int(11) not null,
`PowerId` int(11) not null,
PRIMARY KEY(`SuperId`, `PowerId`)
);
ALTER TABLE `SuperPower`
ADD CONSTRAINT `fk_SuperPower_Super` FOREIGN KEY (`SuperId`) REFERENCES `Super`
(`SuperId`) ON DELETE NO ACTION;
ALTER TABLE `SuperPower`
ADD CONSTRAINT `fk_SuperPower_Power` FOREIGN KEY (`PowerId`) REFERENCES `Power`
(`PowerId`) ON DELETE NO ACTION;
CREATE TABLE IF NOT EXISTS `Sighting` (
`SightingId` int(11) not null auto_increment,
`LocationId` int(11) not null,
`Date` date not null,
PRIMARY KEY(`SightingId`)
);
ALTER TABLE `Sighting`
ADD CONSTRAINT `fk_Sighting_Location` FOREIGN KEY (`LocationId`) REFERENCES `Location`
(`LocationId`) ON DELETE NO ACTION;
CREATE TABLE IF NOT EXISTS `SuperSighting`(
`SuperId` int(11) not null,
`SightingId` int(11) not null,
PRIMARY KEY(`SuperId`, `SightingId`)
);
ALTER TABLE `SuperSighting`
ADD CONSTRAINT `fk_SuperSighting_Super` FOREIGN KEY (`SuperId`) REFERENCES `Super`
(`SuperId`) ON DELETE NO ACTION;
ALTER TABLE `SuperSighting`
ADD CONSTRAINT `fk_SuperSighting_Sighting` FOREIGN KEY (`SightingId`) REFERENCES `Sighting`
(`SightingId`) ON DELETE NO ACTION;