generated from microverseinc/curriculum-template-databases
-
Notifications
You must be signed in to change notification settings - Fork 1
/
shema_based_on_diagram.sql
51 lines (40 loc) · 1.15 KB
/
shema_based_on_diagram.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
CREATE TABLE "animals" (
"id" integer PRIMARY KEY,
"name" varchar(100),
"date_of_birth" date,
"escape_attempts" integer,
"neutered" boolean,
"weight_kg" decimal,
"species_id" integer,
"owners_id" integer
);
CREATE TABLE "owners" (
"id" integer PRIMARY KEY,
"full_name" varchar(100),
"age" integer
);
CREATE TABLE "species" (
"id" integer PRIMARY KEY,
"name" varchar(100)
);
CREATE TABLE "vets" (
"id" integer,
"name" varchar(150),
"age" integer,
"date_of_graduation" date
);
CREATE TABLE "specializations" (
"species_id" integer,
"vet_id" integer
);
CREATE TABLE "visits" (
"animal_id" integer,
"vet_id" integer,
"visit_date" date
);
ALTER TABLE "visits" ADD FOREIGN KEY ("animal_id") REFERENCES "animals" ("id");
ALTER TABLE "vets" ADD FOREIGN KEY ("id") REFERENCES "visits" ("vet_id");
ALTER TABLE "species" ADD FOREIGN KEY ("id") REFERENCES "animals" ("species_id");
ALTER TABLE "specializations" ADD FOREIGN KEY ("species_id") REFERENCES "species" ("id");
ALTER TABLE "specializations" ADD FOREIGN KEY ("vet_id") REFERENCES "vets" ("id");
ALTER TABLE "animals" ADD FOREIGN KEY ("owners_id") REFERENCES "owners" ("id");