-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsozdenie_BD.sql
239 lines (179 loc) · 5.89 KB
/
sozdenie_BD.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
Created: 08.08.2021
Modified: 13.08.2021
Model: MySQL 8.0
Database: MySQL 8.0
*/
-- Create tables section -------------------------------------------------
-- Table Ordering
CREATE DATABASE TV;
USE TV;
CREATE TABLE `Ordering`
(
`Ord_ID` Int NOT NULL AUTO_INCREMENT,
`Ord_Status` Char(120) NOT NULL,
`Ord_Count` Int NOT NULL,
`Ord_Date` Datetime NOT NULL,
`Ord_DatePlan` Datetime NOT NULL,
`Nom_ID` Int NOT NULL,
PRIMARY KEY (`Ord_ID`)
)
;
CREATE INDEX `IX_Relationship2` ON `Ordering` (`Nom_ID`)
;
-- Table Nomenclature
CREATE TABLE `Nomenclature`
(
`Nom_ID` Int NOT NULL,
`Nom_Description` Char(120) NOT NULL,
`Map_ID` Int,
`Spec_ID` Int
)
;
CREATE INDEX `IX_Relationship7` ON `Nomenclature` (`Map_ID`)
;
CREATE INDEX `IX_Relationship13` ON `Nomenclature` (`Spec_ID`)
;
ALTER TABLE `Nomenclature` ADD PRIMARY KEY (`Nom_ID`)
;
-- Table Usage_Log
CREATE TABLE `Usage_Log`
(
`Note_ID` Int NOT NULL,
`Log_Count` Int NOT NULL,
`Ord_ID` Int NOT NULL,
`Nom_ID` Int NOT NULL
)
;
CREATE INDEX `IX_Relationship11` ON `Usage_Log` (`Ord_ID`)
;
CREATE INDEX `IX_Relationship12` ON `Usage_Log` (`Nom_ID`)
;
ALTER TABLE `Usage_Log` ADD PRIMARY KEY (`Note_ID`)
;
-- Table Technological_map
CREATE TABLE `Technological_map`
(
`Map_ID` Int NOT NULL,
`Map_Description` Char(120) NOT NULL
)
;
ALTER TABLE `Technological_map` ADD PRIMARY KEY (`Map_ID`)
;
-- Table Map_Composition
CREATE TABLE `Map_Composition`
(
`Operation_ID` Int NOT NULL,
`Processing_Time` Int NOT NULL,
`Number_Next_Operation` Int,
`Map_ID` Int NOT NULL,
`WC_ID` Int
)
;
CREATE INDEX `IX_Relationship9` ON `Map_Composition` (`WC_ID`)
;
ALTER TABLE `Map_Composition` ADD PRIMARY KEY (`Operation_ID`, `Map_ID`)
;
-- Table Work_Center
CREATE TABLE `Work_Center`
(
`WC_ID` Int NOT NULL,
`WC_status` Char(120) NOT NULL,
`WC_Work_Time` Char(120) NOT NULL
)
;
ALTER TABLE `Work_Center` ADD PRIMARY KEY (`WC_ID`)
;
-- Table Storage
CREATE TABLE `Storage`
(
`Storage_ID` Int NOT NULL,
`Storage_Description` Char(120) NOT NULL
)
;
ALTER TABLE `Storage` ADD PRIMARY KEY (`Storage_ID`)
;
-- Table Specification
CREATE TABLE `Specification`
(
`Spec_ID` Int NOT NULL,
`Spec_Description` Char(100) NOT NULL
)
;
ALTER TABLE `Specification` ADD PRIMARY KEY (`Spec_ID`)
;
-- Table Spec_Composition
CREATE TABLE `Spec_Composition`
(
`Comp_ID` Int NOT NULL,
`Comp_Description` Char(100) NOT NULL,
`Comp_Count` Int NOT NULL,
`Nom_ID` Int,
`Spec_ID` Int NOT NULL
)
;
CREATE INDEX `IX_Relationship15` ON `Spec_Composition` (`Nom_ID`)
;
ALTER TABLE `Spec_Composition` ADD PRIMARY KEY (`Comp_ID`, `Spec_ID`)
;
-- Table Work_Log
CREATE TABLE `Work_Log`
(
`Note_ID` Int NOT NULL,
`Log_Work_Time` Int NOT NULL,
`Output_quantity` Char(100) NOT NULL,
`Ord_ID` Int NOT NULL,
`Nom_ID` Int NOT NULL,
`Operation_ID` Int NOT NULL,
`Map_ID` Int NOT NULL
)
;
CREATE INDEX `IX_Relationship5` ON `Work_Log` (`Ord_ID`)
;
CREATE INDEX `IX_Relationship6` ON `Work_Log` (`Nom_ID`)
;
CREATE INDEX `IX_Relationship10` ON `Work_Log` (`Operation_ID`, `Map_ID`)
;
ALTER TABLE `Work_Log` ADD PRIMARY KEY (`Note_ID`)
;
-- Table Stocks
CREATE TABLE `Stocks`
(
`Nom_ID` Int NOT NULL,
`Storage_ID` Int NOT NULL,
`St_Count` Int NOT NULL
)
;
ALTER TABLE `Stocks` ADD PRIMARY KEY (`Nom_ID`, `Storage_ID`)
;
-- Create foreign keys (relationships) section -------------------------------------------------
ALTER TABLE `Ordering` ADD CONSTRAINT `Consist of Nom` FOREIGN KEY (`Nom_ID`) REFERENCES `Nomenclature` (`Nom_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Stocks` ADD CONSTRAINT `Contains1` FOREIGN KEY (`Nom_ID`) REFERENCES `Nomenclature` (`Nom_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Stocks` ADD CONSTRAINT `Contains2` FOREIGN KEY (`Storage_ID`) REFERENCES `Storage` (`Storage_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Work_Log` ADD CONSTRAINT `Recorded in WL1` FOREIGN KEY (`Ord_ID`) REFERENCES `Ordering` (`Ord_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Work_Log` ADD CONSTRAINT `Recorded in WL2` FOREIGN KEY (`Nom_ID`) REFERENCES `Nomenclature` (`Nom_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Nomenclature` ADD CONSTRAINT `TM is used` FOREIGN KEY (`Map_ID`) REFERENCES `Technological_map` (`Map_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Map_Composition` ADD CONSTRAINT `Consists of TM` FOREIGN KEY (`Map_ID`) REFERENCES `Technological_map` (`Map_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Map_Composition` ADD CONSTRAINT `Uses in` FOREIGN KEY (`WC_ID`) REFERENCES `Work_Center` (`WC_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Work_Log` ADD CONSTRAINT `Recorded in WL3` FOREIGN KEY (`Operation_ID`, `Map_ID`) REFERENCES `Map_Composition` (`Operation_ID`, `Map_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Usage_Log` ADD CONSTRAINT `Recorded in UL1` FOREIGN KEY (`Ord_ID`) REFERENCES `Ordering` (`Ord_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Usage_Log` ADD CONSTRAINT `Recorded in UL2` FOREIGN KEY (`Nom_ID`) REFERENCES `Nomenclature` (`Nom_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Nomenclature` ADD CONSTRAINT `Uses in Nom` FOREIGN KEY (`Spec_ID`) REFERENCES `Specification` (`Spec_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Spec_Composition` ADD CONSTRAINT `Uses in Spec_Comp` FOREIGN KEY (`Nom_ID`) REFERENCES `Nomenclature` (`Nom_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE `Spec_Composition` ADD CONSTRAINT `Consists of` FOREIGN KEY (`Spec_ID`) REFERENCES `Specification` (`Spec_ID`) ON DELETE RESTRICT ON UPDATE RESTRICT
;
ALTER TABLE spec_composition ADD Operation_ID integer;
ALTER TABLE map_composition ADD Operation_desc CHAR(100);