-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototype_of_database.sql
More file actions
159 lines (142 loc) · 3.83 KB
/
Prototype_of_database.sql
File metadata and controls
159 lines (142 loc) · 3.83 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use master;
create database AAA60;
use AAA60;
CREATE TABLE Jobcode
(
JobCode char(1) NOT NULL ,
Description char(10) NULL ,
PRIMARY KEY CLUSTERED (JobCode ASC)
)
go
CREATE TABLE staff
(
PersonID char(4) NOT NULL ,
Name char(20) NULL ,
StartDate date NULL ,
EndDate date NULL ,
JobCode char(1) NULL ,
PRIMARY KEY CLUSTERED (PersonID ASC),
FOREIGN KEY (JobCode) REFERENCES Jobcode(JobCode)
)
go
CREATE TABLE Managers
(
PersonID char(4) NOT NULL ,
LastAccess datetime NULL ,
PRIMARY KEY CLUSTERED (PersonID ASC),
FOREIGN KEY (PersonID) REFERENCES staff(PersonID)
)
go
CREATE TABLE Complex
(
ComplexID char(1) NOT NULL ,
Descripton char(10) NULL ,
PersonID char(4) NULL ,
PRIMARY KEY CLUSTERED (ComplexID ASC),
FOREIGN KEY (PersonID) REFERENCES Managers(PersonID)
)
go
CREATE TABLE Apartment
(
ApartmentID integer NOT NULL ,
Number char(4) NULL ,
ComplexID char(1) NULL ,
NumbeRents integer NULL ,
PRIMARY KEY CLUSTERED (ApartmentID ASC),
FOREIGN KEY (ComplexID) REFERENCES Complex(ComplexID)
)
go
CREATE TABLE Prospectors
(
ProspectNumber integer NOT NULL ,
Name char(20) NULL ,
Phone char(12) NULL ,
Address char(20) NULL ,
PRIMARY KEY CLUSTERED (ProspectNumber ASC)
)
go
CREATE TABLE Status
(
StatusCode integer NOT NULL ,
Description char(10) NULL ,
PRIMARY KEY CLUSTERED (StatusCode ASC)
)
go
CREATE TABLE Waitlist
(
ApartmentID integer NOT NULL ,
ProspectNumber integer NOT NULL ,
StatusCode integer NULL ,
PRIMARY KEY CLUSTERED (ApartmentID ASC,ProspectNumber ASC),
FOREIGN KEY (ApartmentID) REFERENCES Apartment(ApartmentID),
FOREIGN KEY (ProspectNumber) REFERENCES Prospectors(ProspectNumber),
FOREIGN KEY (StatusCode) REFERENCES Status(StatusCode)
)
go
CREATE TABLE Type
(
Type char(1) NOT NULL ,
Description char(10) NULL ,
PRIMARY KEY CLUSTERED (Type ASC)
)
go
CREATE TABLE manualLabour
(
PersonID char(4) NOT NULL ,
PRIMARY KEY CLUSTERED (PersonID ASC),
FOREIGN KEY (PersonID) REFERENCES staff(PersonID)
)
go
CREATE TABLE repair
(
RepairNum integer NOT NULL ,
Description char(10) NULL ,
DateOrdered date NULL ,
DateCompleted date NULL ,
ApartmentID integer NULL ,
Type char(1) NULL ,
PersonID char(4) NULL ,
PRIMARY KEY CLUSTERED (RepairNum ASC),
FOREIGN KEY (ApartmentID) REFERENCES Apartment(ApartmentID),
FOREIGN KEY (Type) REFERENCES Type(Type),
FOREIGN KEY (PersonID) REFERENCES manualLabour(PersonID)
)
go
CREATE TABLE Renter
(
RenterID char(5) NOT NULL ,
Name char(20) NULL ,
PRIMARY KEY CLUSTERED (RenterID ASC)
)
go
CREATE TABLE Lease
(
RenterID char(5) NOT NULL ,
ApartmentID integer NOT NULL ,
Rent money NULL ,
StartDate date NULL ,
PRIMARY KEY CLUSTERED (RenterID ASC,ApartmentID ASC),
FOREIGN KEY (RenterID) REFERENCES Renter(RenterID),
FOREIGN KEY (ApartmentID) REFERENCES Apartment(ApartmentID)
)
go
CREATE TABLE Payment
(
PaymentNumber integer NOT NULL ,
Amount money NULL ,
DateDue date NULL ,
DatePaid date NULL ,
RenterID char(5) NULL ,
ApartmentID integer NULL ,
PRIMARY KEY CLUSTERED (PaymentNumber ASC),
FOREIGN KEY (RenterID,ApartmentID) REFERENCES Lease(RenterID,ApartmentID)
)
go
CREATE TABLE CEO
(
PersonID char(4) NOT NULL ,
NextVisit date NULL ,
PRIMARY KEY CLUSTERED (PersonID ASC),
FOREIGN KEY (PersonID) REFERENCES staff(PersonID)
)
go