├── LICENSE
├── schema.sql
├── data.sql
├── README.md
└── queries.sql
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 NOEL NOMGNE FOKA
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/schema.sql:
--------------------------------------------------------------------------------
1 | /* Database schema to keep the structure of entire database. */
2 |
3 | CREATE TABLE animals (
4 | id INTEGER PRIMARY KEY NOT NULL,
5 | name varchar,
6 | date_of_birth date,
7 | escape_attempts INTEGER,
8 | neutered boolean,
9 | weight_kg decimal
10 | );
11 |
12 | ALTER TABLE animals ADD species varchar(255);
13 |
14 | CREATE TABLE owners (
15 | id serial PRIMARY KEY,
16 | full_name VARCHAR(255),
17 | age INTEGER
18 | );
19 |
20 | CREATE TABLE species (
21 | id serial PRIMARY KEY,
22 | name VARCHAR(155)
23 | );
24 |
25 | ALTER TABLE animals ADD CONSTRAINT animal_id UNIQUE (id);
26 |
27 | ALTER TABLE animals
28 | DROP species,
29 | ADD COLUMN species_id INTEGER,
30 | ADD COLUMN owner_id INTEGER;
31 |
32 | ALTER TABLE animals
33 | ADD CONSTRAINT fk_species FOREIGN KEY (species_id) REFERENCES species(id),
34 | ADD CONSTRAINT fk_owner FOREIGN KEY (owner_id) REFERENCES owners(id);
35 |
36 | create table vets(
37 | id int primary key generated always as identity,
38 | name varchar(50),
39 | age int,
40 | date_of_graduation date
41 | );
42 |
43 | create table specializations (
44 | species_id int,
45 | vet_id int,
46 | primary key(species_id, vet_id),
47 | constraint fk_species
48 | foreign key (species_id)
49 | references species(id),
50 | constraint fk_vets
51 | foreign key(vet_id)
52 | references vets(id)
53 | );
54 |
55 | create table visits(
56 | animal_id int,
57 | vet_id int,
58 | date_of_visits date,
59 | constraint fk_animals
60 | foreign key(animal_id)
61 | references animals(id),
62 | constraint fk_vets
63 | foreign key(vet_id)
64 | references vets(id)
65 | );
--------------------------------------------------------------------------------
/data.sql:
--------------------------------------------------------------------------------
1 | /* Populate database with sample data. */
2 |
3 | INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
4 | VALUES (1, 'Agumon', '2020-02-03', 0, true, 10.23);
5 |
6 | INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
7 | VALUES (2, 'Gabumon', '2018-11-15', 2, true, 8);
8 |
9 | INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
10 | VALUES (3, 'Pikachu', '2021-01-07', 1, false, 15.04);
11 |
12 | INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg)
13 | VALUES (4, 'Devimon', '2017-05-12', 5, true, 11);
14 |
15 | INSERT INTO animals (id, name, date_of_birth, escape_attempts, neutered, weight_kg)
16 | VALUES (5, 'Charmander', '2020-02-08', 0, FALSE, -11),
17 | (6, 'Plantmon', '2021-11-15', 2, TRUE, -5.7),
18 | (7, 'Squirtle', '1993-04-02', 3, FALSE, -12.13),
19 | (8, 'Angemon', '2005-06-12', 1, TRUE, -45),
20 | (9, 'Boarmon', '2005-06-07', 7, TRUE, 20.4),
21 | (10, 'Blossom', '1998-10-13', 3, TRUE, 17),
22 | (11, 'Ditto', '2022-05-14', 4, TRUE, 22) ;
23 |
24 | INSERT INTO owners (full_name, age)
25 | VALUES ('Sam Smith', 34),
26 | ('ennifer Orwell', 19),
27 | ('Bob', 45),
28 | ('Melody Pond', 77),
29 | ('Dean Winchester', 14),
30 | ('Jodie Whittaker', 38);
31 |
32 | INSERT INTO species (name)
33 | VALUES ('Pokemon'), ('Digimon');
34 |
35 | UPDATE animals SET species_id = (
36 | CASE
37 | WHEN name LIKE '%mon' THEN (SELECT id FROM species WHERE name = 'Digimon')
38 | ELSE (SELECT id FROM species WHERE name = 'Pokemon')
39 | END
40 | );
41 |
42 | update animals set owner_id = case
43 | when name = 'Agumon' then 1
44 | when name in ('Gabumon', 'Pikachu') then 2
45 | when name in ('Devimon', 'Plantmon') then 3
46 | when name in ('Charmander', 'Squirtle', 'Blossom') then 4
47 | when name in ('Angemon', 'Boarmon') then 5
48 | end;
49 |
50 | insert into vets(name, age, date_of_graduation) values
51 | ('Vet William Tatcher', 45, '2000-04-23'),
52 | ('Vet Maisy Smith', 26, '2019-01-17'),
53 | ('Vet Stephanie Mendez', 64, '1981-05-04'),
54 | ('Vet Jack Harkness', 38, '2008-06-08');
55 |
56 | insert into specializations(species_id, vet_id) values
57 | (1, 1), (1,3), (2,3), (2,4);
58 |
59 | insert into visits(animal_id,vet_id ,date_of_visits) values
60 | (1,1,'2020-05-24'), (1,3,'2020-07-22'), (2,4,'2021-02-02'),
61 | (3,2,'2020-01-05'), (3,2,'2020-03-08'), (3,2,'2020-05-14'),
62 | (4,3,'2021-05-04'), (5,4,'2021-02-24'), (6,2,'2019-12-21'),
63 | (6,1,'2020-08-10'), (6,2,'2021-04-07'), (7,3,'2019-09-29'),
64 | (8,4,'2020-10-03'), (8,4,'2020-11-04'), (9,2,'2019-01-24'),
65 | (9,2,'2019-05-15'), (9,2,'2020-02-27'), (9,2,'2020-08-03'),
66 | (10,3,'2020-05-24'), (10,1,'2021-01-11');
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vet clinic database
2 |
3 | ## Getting Started
4 |
5 | This repository includes files with plain SQL that can be used to recreate a database:
6 |
7 | - Use [schema.sql](./schema.sql) to create all tables.
8 | - Use [data.sql](./data.sql) to populate tables with sample data.
9 | - Check [queries.sql](./queries.sql) for examples of queries that can be run on a newly created database. **Important note: this file might include queries that make changes in the database (e.g., remove records). Use them responsibly!**
10 |
11 |
12 |
13 |
34 |
35 |
36 |
37 |
38 | # 📗 Table of Contents
39 |
40 | - [Vet clinic database](#vet-clinic-database)
41 | - [Getting Started](#getting-started)
42 | - [📗 Table of Contents](#-table-of-contents)
43 | - [📖 Vet clinic database ](#-vet-clinic-database-)
44 | - [🛠 Built With SQL](#-built-with-sql)
45 | - [Tech Stack posgreSQL](#tech-stack-posgresql)
46 | - [Key Features ](#key-features-)
47 | - [💻 Getting Started ](#-getting-started-)
48 | - [Prerequisites](#prerequisites)
49 | - [Setup](#setup)
50 | - [Usage](#usage)
51 | - [👥 Author ](#-author-)
52 | - [🔭 Future Features ](#-future-features-)
53 | - [🤝 Contributing ](#-contributing-)
54 | - [⭐️ Show your support ](#️-show-your-support-)
55 | - [🙏 Acknowledgments ](#-acknowledgments-)
56 | - [📝 License ](#-license-)
57 |
58 |
59 |
60 | # 📖 Vet clinic database
61 |
62 | **Vet clinic database** is a...
63 |
64 | ## 🛠 Built With SQL
65 |
66 | ### Tech Stack posgreSQL
67 |
68 | Client
70 |
71 |
73 | Server
77 |
78 |
80 | Database
84 |
85 |
87 |