generated from microverseinc/curriculum-template-databases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.sql
169 lines (119 loc) · 3.9 KB
/
data.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
/* Populate database with sample data. */
-- First Project
INSERT INTO animals VALUES (1,'Agumon', '2020-FEB-03', 0, TRUE, 10.23);
INSERT INTO animals VALUES (2,'Gabumon', '2018-NOV-15', 2, TRUE, 8);
INSERT INTO animals VALUES (3,'Pikachu', '2021-JAN-07', 1, FALSE, 15.04);
INSERT INTO animals VALUES (4,'Devimon', '2017-MAY-12', 5, TRUE, 11);
-- Second Project
INSERT INTO animals VALUES (1,'Charmander', '2020-Feb-08', 0, false, -11);
INSERT INTO animals VALUES (2,'Plantmon', '2021-Nov-15', 2, true, -5.7);
INSERT INTO animals VALUES (3,'Squirtle', '1993-Apr-02', 3, false, -12.13);
INSERT INTO animals VALUES (4,'Angemon', '2005-Jun-12', 1, true, -45);
INSERT INTO animals VALUES (5,'Boarmon', '2005-Jun-07', 7, true, 20.4);
INSERT INTO animals VALUES (6,'Blossom', '1998-Oct-13', 3, true, 17);
INSERT INTO animals VALUES (7,'Ditto', '2022-May-14', 4, true, 22);
-- TRANSACTION 01
BEGIN;
UPDATE animals
SET species = 'unspecified';
SELECT * FROM animals;
ROLLBACK;
-- TRANSACTION 02
BEGIN;
UPDATE animals
SET species = 'digimon'
WHERE name LIKE '%mon';
UPDATE animals
SET species = 'pokemon'
WHERE species IS NULL;
COMMIT;
SELECT * FROM animals;
-- TRANSACTION 03
BEGIN;
DELETE FROM animals;
SELECT * FROM animals;
ROLLBACK;
-- TRANSACTION 04
BEGIN;
DELETE FROM animals
WHERE TO_CHAR(date_of_birth,'YYYY-MON-DD') > '2022-JAN-01';
SAVEPOINT SP1;
UPDATE animals
SET weight_kg = weight_kg*-1;
ROLLBACK TO SAVEPOINT SP1;
UPDATE animals
SET weight_kg = weight_kg*-1
WHERE weight_kg < 0;
COMMIT;
-- Third Project
-- Owners Information
INSERT INTO owners (full_name, age) VALUES ('Sam Smith', 34);
INSERT INTO owners (full_name, age) VALUES ('Jennifer Orwell', 19);
INSERT INTO owners (full_name, age) VALUES ('Bob', 45);
INSERT INTO owners (full_name, age) VALUES ('Melody Pond', 77);
INSERT INTO owners (full_name, age) VALUES ('Dean Winchester', 14);
INSERT INTO owners (full_name, age) VALUES ('Jodie Whittaker', 38);
-- Species Information
INSERT INTO species(name) VALUES ('Digimon');
INSERT INTO species(name) VALUES ('Pokemon');
-- Updations
-- OWNER'S UPDATIONS
UPDATE animals
SET species_id = 1
WHERE name LIKE '%mon';
UPDATE animals
SET species_id = 2
WHERE name NOT LIKE '%mon';
-- SPECIES UPDATIONS
UPDATE animals
SET owner_id = 1
WHERE name = 'Agumon';
UPDATE animals
SET owner_id = 2
WHERE name IN ('Gabumon', 'Pikachu');
UPDATE animals
SET owner_id = 3
WHERE name IN ('Devimon', 'Plantmon');
UPDATE animals
SET owner_id = 4
WHERE name IN ('Charmander', 'Squirtle', 'Blossom');
UPDATE animals
SET owner_id = 5
WHERE name IN ('Angemon', 'Boarmon');
-- Fourth Project
INSERT INTO vets(name, age, date_of_graduation) VALUES
('William Tatcher', 45, '2000-Apr-23'),
('Maisy Smith', 26, '2019-Jan-17'),
('Stephanie Mendez', 64, '1981-May-04'),
('Jack Harkness', 38, '2008-Jun-08');
INSERT INTO specializations VALUES
(2, 1),
(1, 3),
(2, 3),
(1, 4);
INSERT INTO visits VALUES
(7,1, '2020-May-24'),
(7,3, '2020-Jul-22'),
(8,4, '2021-Feb-02'),
(9,2, '2020-Jan-05'),
(9,2, '2020-Mar-08'),
(9,2, '2020-May-14'),
(10,3, '2021-May-04'),
(1,4, '2021-Feb-24'),
(2,2, '2019-Dec-21'),
(2,1, '2020-Aug-10'),
(2,2, '2021-Apr-07'),
(3,3, '2019-Sep-29'),
(4,4, '2020-Oct-03'),
(4,4, '2020-Nov-04'),
(5,2, '2019-Jan-24'),
(5,2, '2019-May-15'),
(5,2, '2020-Feb-27'),
(5,2, '2020-Aug-03'),
(6,3, '2020-May-24'),
(6,1, '2021-Jan-11');
-- Project 05
-- This will add 3.594.280 visits considering you have 10 animals, 4 vets, and it will use around ~87.000 timestamps (~4min approx.)
INSERT INTO visits (animal_id, vet_id, date_of_visit) SELECT * FROM (SELECT id FROM animals) animal_ids, (SELECT id FROM vets) vets_ids, generate_series('1980-01-01'::timestamp, '2021-01-01', '4 hours') visit_timestamp;
-- This will add 2.500.000 owners with full_name = 'Owner <X>' and email = 'owner_<X>@email.com' (~2min approx.)
insert into owners (full_name, email) select 'Owner ' || generate_series(1,2500000), 'owner_' || generate_series(1,2500000) || '@mail.com';