· 7 years ago · Dec 03, 2018, 02:22 PM
1-- DDL
2
3-- (1) DROPS
4-- (2) CREATE TABLES
5-- (3) INSERT VALUES
6-- (4) CREATE VIEWS
7-- (5) CREATE TRIGGERS/PROCEDURES
8
9DROP TABLE IF EXISTS dig_extension;
10DROP TABLE IF EXISTS slides;
11DROP TABLE IF EXISTS books;
12DROP TABLE IF EXISTS digs;
13DROP TABLE IF EXISTS artefacts;
14DROP TABLE IF EXISTS documents;
15DROP TABLE IF EXISTS persons;
16
17
18
19
20-- person (person_id, p_name)
21CREATE TABLE persons (
22 PRIMARY KEY(p_id),
23
24 p_id INT,
25 firstname VARCHAR(35),
26 lastname VARCHAR(35),
27);
28
29-- documents (document_id, title, published_year, d_location, author, person)
30CREATE TABLE documents (
31 PRIMARY KEY(d_id),
32
33 d_id INT,
34 title VARCHAR(30),
35 published_year INT,
36 d_location VARCHAR(30),
37 author VARCHAR(30),
38 person INT,
39
40 FOREIGN KEY (person)
41 REFERENCES persons(p_id)
42 );
43
44-- artefacts(a_id, sequential_artefact, coordinate, depth, date_found, description, location, date_out, date_back)
45
46
47
48CREATE TABLE artefacts(
49 PRIMARY KEY(a_id, sequential_artefact),
50
51 a_id AS CONCAT (dig_id, '-', sequential_artefact) PERSISTED NOT NULL,
52 sequential_artefact INT,
53 coordinate VARCHAR(30),
54 depth VARCHAR(30),
55 date_found DATE,
56 descritpion VARCHAR(50),
57 a_location VARCHAR(30),
58 date_out DATE,
59 date_back DATE,
60 person INT,
61 dig_site VARCHAR(100),
62 dig_id INT,
63
64 FOREIGN KEY (person)
65 REFERENCES persons(p_id)
66
67-- FOREIGN KEY (a_dig_site)
68-- REFERENCES dig_extension(dig_site)
69
70-- FOREIGN KEY (a_dig_id)
71-- REFERENCES dig_extension(dig_id)
72);
73 SELECT CONCAT (dig_id, '-', sequential_artefact) FROM artefacts;
74-- digs( d_dig_site, d_dig_id, d_description, d_p_id)
75
76CREATE TABLE digs (
77 PRIMARY KEY (dig_site, dig_id),
78
79 dig_site VARCHAR(100),
80 dig_id INT,
81 d_description VARCHAR(250),
82 p_id INT,
83
84 FOREIGN KEY (p_id)
85 REFERENCES persons(p_id),
86
87);
88
89CREATE TABLE books(
90 PRIMARY KEY (b_id),
91
92 b_id INT,
93 title VARCHAR(30),
94 published_year VARCHAR(10),
95 author VARCHAR(35),
96 date_out DATE,
97 b_location VARCHAR(50),
98 date_back DATE,
99 person INT,
100
101 FOREIGN KEY (person)
102 REFERENCES persons(p_id)
103);
104
105CREATE TABLE slides(
106 PRIMARY KEY (s_id, sequential_slide),
107
108 s_id INT,
109 sequential_slide INT,
110 s_subject VARCHAR(35),
111 s_description VARCHAR(35),
112 date_out DATE,
113 date_back DATE,
114 s_location VARCHAR(35),
115 person_id INT,
116 dig_site VARCHAR(100),
117 dig_id INT,
118
119
120 FOREIGN KEY (person_id)
121 REFERENCES persons(p_id),
122
123 FOREIGN KEY (dig_site, dig_id)
124 REFERENCES digs(dig_site, dig_id)
125);
126
127SELECT COL_LENGTH ( 'artefacts', 'a_id')
128
129CREATE TABLE dig_extension(
130
131 -- PRIMARY KEY(id, sequential_artefact, dig_site, dig_id,b_id, s_id, sequential_slide),
132
133 id VARCHAR (25),
134 sequential_artefact INT,
135 dig_site VARCHAR(100),
136 dig_id INT,
137 b_id INT,
138 s_id INT,
139 sequential_slide INT,
140
141 FOREIGN KEY (id, sequential_artefact)
142 REFERENCES artefacts (a_id, sequential_artefact),
143
144 FOREIGN KEY (dig_site, dig_id)
145 REFERENCES digs(dig_site, dig_id),
146
147 FOREIGN KEY (b_id)
148 REFERENCES books (b_id),
149
150 FOREIGN KEY (s_id, sequential_slide)
151 REFERENCES slides (s_id, sequential_slide)
152);
153
154
155
156
157
158 INSERT INTO persons (p_id, firstname, lastname)
159 VALUES (21, 'Bengt', 'Andersson'),
160 (32, 'Anna', 'Nilsson'),
161 (33, 'Johan', 'Ahlberg'),
162 (97, 'Anders', 'Svensson'),
163 (12, 'Jennifer', 'Berg'),
164 (11, 'Emelie', 'Palner'),
165 (77, 'Elinor', 'Nyberg'),
166 (87, 'Hannes', 'Lindgren'),
167 (99, 'Jacob', 'Lycke'),
168 (94, 'Olivia', 'Wennborg'),
169 (55, 'Johan', 'Haggar'),
170 (67, 'Axel', 'Guditz'),
171 (61, 'Jonathan', 'Solberg'),
172 (81, 'Sara', 'Andersdotter'),
173 (85, 'Amanda', 'Silfversparre'),
174 (74, 'Niklas', 'Guldsked'),
175 (49, 'Sven', 'Laxnacke'),
176 (41, 'Calle', 'Hoffeinheim');
177
178
179 INSERT INTO documents (d_id, title, published_year, d_location, author, person)
180 VALUES (392, 'Life On Earth', 1992, 'Shelf: A', 'James Cameron', 41),
181 (3582, 'Book Of Life', 2002, 'Shelf: D', 'Niklas Berg', 85),
182 (4921, 'Artefacts 101', 1952, 'Shelf: B', 'Gunnar Martin', 94),
183 (353, 'Cosmos', 2016, 'Shelf: C', 'Joseph Bang', 77),
184 (981, 'Space', 2002, 'Shelf: G', 'Anna Smith', 49),
185 (111, 'Moon landing 1969', 1970, 'Shelf: C', 'Anna Smith', 12),
186 (455, 'Festerist 101', 1994, 'Shelf: A', 'Clarence Coleman', 97),
187 (12, 'History of Tour de France', 2005, 'Shelf: A', 'Phil Stevenson', 87),
188 (71, 'How to dig a tunnel', 2010, 'Shelf: A', 'Christopher O.Neil', 33),
189 (9746, 'Basejump', 2013, 'Shelf: B', 'Dustin Hoffman', 32),
190 (32221, 'History of dinosaurs', 1987, 'Shelf C', 'Michael Bay', 21),
191 (4942837, 'Formel 1', 2018, 'Shelf: D', 'Stan Lee', 55);
192
193
194 INSERT INTO books (b_id, title, published_year, author, date_out, date_back, b_location, person)
195 VALUES (123, 'FOR AZEROTH!', 2007,'Dillon McNillon', '2018-11-05 ','2018-12-05 ', 'Borrowed', 77),
196 (435, 'National Treasure', 2003, 'Nicolas Cage', ' ', ' ', 'Shelf:A22', 41 ),
197 (563, 'WAOOW', 2001, 'Owen Wilson', ' ', ' ', 'Shelf:A22', 12),
198 (152, 'Nonstop', 2018, 'Drake', '2018-10-12', '2018-11-12', 'Borrowed', 99),
199 (880, 'Bridget Jones dagbok', 2002, 'Yung Nylla', ' ', ' ', 'Shelf:B12', 49),
200 (981, 'Life of Dillon', 2001, 'John Cleese', '2018-09-11', '2018-10-11', 'Borrowed', 67),
201 (654, 'Hejhej', 2005, 'J&J', '2018-08-23', '2018-09-23', 'Borrowed', 21);
202
203
204
205
206
207
208 INSERT INTO digs (dig_site, dig_id, d_description, p_id)
209 VALUES ('Chan-Chan', 12, 'Beach on the coast of the commune of MehuÃn in southern Chile.', 41),
210 ('Monte Verde', 43, 'Monte Verde is an archaeological site in southern Chile, located near Puerto Montt, Southern Chile', 21),
211 ('Fell Cave', 9, 'Cueva Fell is a natural cave and archaeological site in southern Patagonia.', 32),
212 ('Pali Aike', 4, 'The Pali-Aike National Park is a park located in the Magallanes Region of the Chilean Patagonia.', 99),
213 ('An Yang', 6, 'An yang is a prefecture-level city in Henan province, China.', 67),
214 ('Kykkos Monastery', 21, 'Kykkos Monastery which lies 20 km west of Pedoulas, is one of the wealthiest and best-known monasteries in Cyprus.', 85),
215 ('Notre Dame de tyre', 67, 'Notre Dame de Tyre or Our Lady of Tyre is a monastic church in Nicosia.', 41);
216
217
218 INSERT INTO artefacts (sequential_artefact, coordinate, depth, date_found, descritpion, a_location, date_out, date_back, person, dig_site, dig_id)
219 VALUES (465, '30:40', '20 cm', '2017-05-23', 'Small round object', 'Borrowed', '2017-12-01', '2017-12-24', 55, 'Chan-Chan', 12),
220 (266, '30:45', '15 cm', '2017-05-23', 'Small round object', 'Borrowed', '2017-12-01', '2017-12-24', 67, 'Monteverde', 43),
221 (266, '30:35', '39 cm', '2017-05-23', 'Small round object', 'Borrowed', '2017-12-01', '2017-12-24', 81, 'Fell Cave', 9),
222
223 (275, '32:42', '10 cm', '1997-05-29', 'Silver coin', 'Borrowed', '2017-12-01', '2017-12-24', 21, 'An Yang', 6),
224 (765, '32:42', '180 cm', '1997-05-12', 'Gold Coin', 'Borrowed', '2017-12-01', '2017-12-24', 41, 'An Yang', 6),
225 (865, '32:42', '20 cm', '1997-05-27', 'Chinese sword', 'Borrowed', '2017-12-01', '2017-12-24', 41, 'An Yang', 6),
226 (145, '32:32', '0.5 cm', '1997-01-12', 'Chinese golden knife', 'Borrowed', '2017-12-01', '2017-12-24', 77, 'An Yang', 6),
227 (132, '32:41', '200 cm', '1997-09-01', 'Chinese helmet', 'Borrowed', '2017-12-01', '2017-12-24', 41, 'An Yang', 6),
228 (166, '29:45', '234 cm', '1997-07-14', 'Chinese breast plate', 'Borrowed', '2017-12-01', '2017-12-24', 77, 'An Yang', 6),
229 (125, '27:43', '500 cm', '1997-06-14', 'Chinese shield', 'Borrowed', '2017-12-01', '2017-12-24', 41, 'An Yang', 6),
230
231 (151, '12:92:14', '37 cm', '1999-02-24', 'Wooden crucifix', 'In-House', NULL, NULL, 94, 'Kykkos Monastery', 21),
232 (118, '30:40:21', '94 cm', '1992-05-19', 'Golden ring', 'In-House', NULL, NULL, 81, 'Kykkos Monastery', 21),
233 (119, '30:40:23', '122 cm', '1993-08-17', 'Monk cape', 'In-House', NULL, NULL, 94, 'Kykkos Monastery', 21),
234 (117, '30:40:55', '431 cm', '1992-01-12', 'Golden chain', 'In-House', NULL, NULL, 12, 'Kykkos Monastery', 21),
235 (110, '30:40:12', '12 cm', '1992-08-24', 'Candle holder', 'In-House', NULL, NULL, 94, 'Kykkos Monastery', 21),
236 (109, '30:40:98', '542 cm', '1992-02-02', 'Golden candle holder', 'In-House', NULL, NULL, 61, 'Kykkos Monastery', 21),
237 (108, '30:40:24', '122 cm', '1993-02-23', 'Metal crucifix', 'In-House', NULL, NULL, 99, 'Kykkos Monastery', 21),
238 (102, '30:40:77', '32 cm', '1993-05-29', 'Wooden bowl', 'In-House', NULL, NULL, 99, 'Kykkos Monastery', 21),
239 (100, '30:40:98', '96 cm', '1992-06-28', 'black priest cape', 'In-House', NULL, NULL, 94, 'Kykkos Monastery', 21),
240
241 (964, '98:34', '200 cm', '2015-02-23', 'wolf skeleton', 'Borrowed', '2016-04-01', '2019-01-10', 41, 'Pali Aike', 4),
242 (965, '95:42', '95 cm', '2015-03-24', 'Puma skeleton', 'Borrowed', '2016-04-01', '2019-01-10', 74, 'Pali Aike', 4),
243 (936, '93:43', '94 cm', '2015-03-22', 'Patagonian Hairy Armadillo', 'Borrowed', '2016-04-01', '2019-01-10', 74, 'Pali Aike', 4),
244
245 (462, '432:431', '0,1 cm', '1992-04-11', 'Old brick wall', 'Borrowed', '1992-12-01', '2017-12-24', 11, 'Notre Dame de tyre', 67),
246
247 (732, '84:42', '43 cm', '2013-05-21', 'Stuffed Lizard', 'In-House', NULL, NULL, 99, 'Monteverde', 43),
248 (757, '82:53', '53 cm', '2013-08-22', 'Snake skin', 'In-House', NULL, NULL, 33, 'Monteverde', 43),
249 (752, '81:95', '123 cm', '2017-08-19', 'Puma Skeleton', 'In-House', NULL, NULL, 97, 'Monteverde', 43),
250
251
252 (343, '11:40', '13 cm', '1982-01-23', 'Fish skeleton', 'In-house',NULL, NULL, 87, 'Fell Cave', 9),
253 (365, '11:42', '11 cm', '1983-04-13', 'Big fish skeleton', 'In-House', NULL, NULL, 55, 'Fell Cave', 12),
254 (375, '11:53', '8 cm', '1982-06-19', 'Medium fish skeleton', 'In-House', NULL, NULL, 55, 'Fell Cave', 12),
255 (392, '11:52', '1.5 cm', '1983-05-29', 'Random fish skeleton', 'In-House', NULL, NULL, 55, 'Fell Cave', 12),
256 (326, '11:39', '5.5 cm', '1982-09-27', 'Old seaweed', 'Borrowed', '1997-05-29', '1997-09-29', 55, 'Fell Cave', 12),
257
258 (753, '321:401', '00 cm', '1999-05-23', 'Rock statue', 'Borrowed', '2018-12-03', '2019-04-24', 21, 'Chan-Chan', 12),
259 (725, '324:402', '45 cm', '1999-03-23', 'Wooden statue', 'Borrowed', '2018-12-03', '2019-04-24', 67, 'Chan-Chan', 12),
260 (769, '381:471', '921 cm', '1999-06-28', 'Metal statue', 'Borrowed', '2018-12-03', '2019-04-24', 33, 'Chan-Chan', 12),
261 (726, '339:412', '549 cm', '2000-03-12', 'Round random thing', 'Borrowed', '2018-12-03', '2019-04-24', 85, 'Chan-Chan', 12),
262
263
264
265 (212, '282:52', '70 cm', '2017-02-22', 'Small round object', 'In-House', NULL, NULL, 55, 'Chan-Chan', 12),
266 (214, '284:42', '30 cm', '2017-05-23', 'Dinosaur bone', 'Borrowed', '2018-12-01', '2019-01-24', 41, 'Chan-Chan', 12),
267 (285, '295:15', '65 cm', '2017-03-18', 'Skin bone', 'In-House', NULL, NULL, 11, 'Fell Cave', 9),
268 (286, '251:12', '800 cm', '2015-05-23', 'Mammoth', 'In-House', NULL, NULL, 97, 'Chan-Chan', 12),
269 (203, '295:09', '300 cm', '2012-11-23', 'Haggar', 'Borrowed', '2018-10-01', '2019-02-24', 55, 'Chan-Chan', 12),
270
271 (434, '302:140', '80 cm', '2002-02-06', 'Small round object', 'Borrowed', '2018-10-01', '2019-03-24', 55, 'An Yang', 6),
272 (491, '350:470', '470 cm', '2004-03-12', 'Big round object', 'In-House', NULL, NULL, 61, 'Pali Aike', 4),
273 (461, '730:430', '205 cm', '2007-06-21', 'Small round object', 'Borrowed', '2018-12-01', '2019-12-24', 55, 'Chan-Chan', 12),
274
275 (453, '230:240', '240 cm', '2011-02-23', 'Small round object', 'Borrowed', '2018-12-01', '2019-01-24', 55, 'Chan-Chan', 12),
276 (361, '530:340', '120 cm', '2013-01-23', 'Small round object', 'Borrowed', '2018-12-01', '2017-01-14', 55, 'Chan-Chan', 12);