generated from microverseinc/curriculum-template-databases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
40 lines (30 loc) · 756 Bytes
/
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
/* Database schema to keep the structure of entire database. */
CREATE TABLE animals (
id INT GENERATED ALWAYS AS IDENTITY,
name VARCHAR(250),
date_of_birth DATE,
escape_attempts INT,
neutered BOOLEAN,
weight_kg DECIMAL,
species VARCHAR(250)
);
CREATE TABLE owners (
id SERIAL NOT NULL,
full_name VARCHAR(250),
age INT,
PRIMARY KEY (id)
);
CREATE TABLE species (
id SERIAL NOT NULL,
name VARCHAR(250),
PRIMARY KEY (id)
);
ALTER TABLE animals
ADD COLUMN species_id INT,
ADD FOREIGN KEY (species_id) REFERENCES species(id)
ON DELETE CASCADE;
ALTER TABLE animals
ADD COLUMN owner_id INT,
ADD FOREIGN KEY (owner_id) REFERENCES owners(id)
ON DELETE CASCADE;
ALTER TABLE visits DROP PRIMARY KEY;