-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
74 lines (62 loc) · 1.42 KB
/
schema.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
-- Table for Animal
CREATE TABLE animals (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
date_of_birth DATE NOT NULL,
escape_attempts INT NOT NULL,
neutered BOOLEAN NOT NULL,
weight_kg DECIMAL(10, 2) NOT NULL
);
-- Animal Table Alter
ALTER TABLE
animals
ADD
COLUMN species VARCHAR(100);
-- Animal Table Alter Change Column Name
ALTER TABLE
animals
ADD
COLUMN species_id INT REFERENCES species(id);
-- Animal Table Alter Change Column
ALTER TABLE
animals
ADD
COLUMN owner_id INT REFERENCES owners(id);
-- Drop Column from Animal Table
ALTER TABLE
animals DROP COLUMN species;
-- Table for Owners
CREATE TABLE owners (
id SERIAL PRIMARY KEY,
full_name VARCHAR(255),
age INT
);
-- Table for Species
CREATE TABLE species (
id SERIAL PRIMARY KEY,
name VARCHAR(255)
);
-- Table for vets
CREATE TABLE vets (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
age INT,
date_of_graduation DATE
);
-- Table for Specializations
CREATE TABLE specializations (
id SERIAL PRIMARY KEY,
vet_id INT REFERENCES vets(id),
species_id INT REFERENCES species(id)
);
-- Table for Visits
CREATE TABLE visits (
id SERIAL PRIMARY KEY,
vet_id INT REFERENCES vets(id),
animal_id INT REFERENCES animals(id),
visit_date DATE
);
-- EXPLAIN ANALYZE
CREATE INDEX INX_A ON VISIT(animal_id ASC);
CREATE INDEX V ON VISIT(vet_id ASC);
CREATE INDEX INX_O ON OWNERS(EMAIL);