-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathQueries.sql
More file actions
71 lines (63 loc) · 1.86 KB
/
Queries.sql
File metadata and controls
71 lines (63 loc) · 1.86 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
-- Queries:
-- Tables Created: -
-- Personnel Table
CREATE TABLE Personnel (
personnel_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
post VARCHAR(50),
unit_id INT,
role VARCHAR(50),
status ENUM('active', 'injured', 'MIA', 'KIA'),
contact_information VARCHAR(100)
);
-- Location table:
CREATE TABLE Locations (
location_id INT PRIMARY KEY,
name VARCHAR(100),
coordinates VARCHAR(100)
);
-- Units Table:
CREATE TABLE Units (
unit_id INT PRIMARY KEY,
unit_name VARCHAR(50),
unit_type ENUM('infantry', 'cavalry', 'artillery'),
commander_id INT,
location_id INT,
FOREIGN KEY (commander_id) REFERENCES Personnel(personnel_id) ON DELETE SET NULL,
FOREIGN KEY (location_id) REFERENCES Locations(location_id) ON DELETE CASCADE
);
-- Missions table:
CREATE TABLE Missions (
mission_id INT PRIMARY KEY,
name VARCHAR(100),
objective TEXT,
start_date varchar(20),
end_date varchar(20),
status ENUM('planned', 'ongoing', 'completed'),
location_id INT,
FOREIGN KEY (location_id) REFERENCES Locations(location_id) ON DELETE CASCADE
);
-- Equipment Table:
CREATE TABLE Equipment (
equipment_id INT PRIMARY KEY,
name VARCHAR(100),
type ENUM('Weapon', 'Vehicle', 'Electronic', 'Other'),
unit_id INT,
status ENUM('Operational', 'Maintenance', 'Decommissioned'),
location_id INT,
FOREIGN KEY (unit_id) REFERENCES Units(unit_id) ON DELETE CASCADE,
FOREIGN KEY (location_id) REFERENCES Locations(location_id) ON DELETE CASCADE
);
-- Supplies Table
CREATE TABLE Supplies (
supply_id INT PRIMARY KEY,
name VARCHAR(100),
type VARCHAR(50),
quantity INT,
unit_id INT,
location_id INT,
status ENUM('Available', 'In Use', 'Out of Stock') DEFAULT 'Available',
FOREIGN KEY (unit_id) REFERENCES Units(unit_id) ON DELETE CASCADE,
FOREIGN KEY (location_id) REFERENCES Locations(location_id) ON DELETE CASCADE
);