diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1a17746 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Ajayi Ridwan Olalekan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/QueriesOuput/Day2/query1.png b/QueriesOuput/Day2/query1.png new file mode 100644 index 0000000..c1694c9 Binary files /dev/null and b/QueriesOuput/Day2/query1.png differ diff --git a/QueriesOuput/Day2/query2.png b/QueriesOuput/Day2/query2.png new file mode 100644 index 0000000..feaf022 Binary files /dev/null and b/QueriesOuput/Day2/query2.png differ diff --git a/QueriesOuput/Day2/query3.png b/QueriesOuput/Day2/query3.png new file mode 100644 index 0000000..15a4118 Binary files /dev/null and b/QueriesOuput/Day2/query3.png differ diff --git a/QueriesOuput/Day2/query4.png b/QueriesOuput/Day2/query4.png new file mode 100644 index 0000000..4350faa Binary files /dev/null and b/QueriesOuput/Day2/query4.png differ diff --git a/QueriesOuput/Day2/query5.png b/QueriesOuput/Day2/query5.png new file mode 100644 index 0000000..355cea4 Binary files /dev/null and b/QueriesOuput/Day2/query5.png differ diff --git a/QueriesOuput/Day2/query6.png b/QueriesOuput/Day2/query6.png new file mode 100644 index 0000000..0126789 Binary files /dev/null and b/QueriesOuput/Day2/query6.png differ diff --git a/QueriesOuput/Day2/query7.png b/QueriesOuput/Day2/query7.png new file mode 100644 index 0000000..e22dd1b Binary files /dev/null and b/QueriesOuput/Day2/query7.png differ diff --git a/QueriesOuput/Day2/query8.png b/QueriesOuput/Day2/query8.png new file mode 100644 index 0000000..653ae57 Binary files /dev/null and b/QueriesOuput/Day2/query8.png differ diff --git a/README.md b/README.md index dd41aa8..de3f3e9 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,3 @@ -# curriculum-databases-projects-template - -> This template should be used for database related projects at Microverse. -> Generate your own repository, update this README and edit all files content while working on projects. You should not be adding any new files unless asked otherwise. - - -## Getting Started - -This repository includes files with plain SQL that can be used to recreate a database: - -- Use [schema.sql](./schema.sql) to create all tables. -- Use [data.sql](./data.sql) to populate tables with sample data. -- 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!** - - - - - - # 📗 Table of Contents @@ -45,180 +6,90 @@ After you're finished please remove all the comments and instructions! - [🛠 Built With](#built-with) - [Tech Stack](#tech-stack) - [Key Features](#key-features) - - [🚀 Live Demo](#live-demo) - [💻 Getting Started](#getting-started) - [Setup](#setup) - [Prerequisites](#prerequisites) - [Install](#install) - - [Usage](#usage) - - [Run tests](#run-tests) - - [Deployment](#triangular_flag_on_post-deployment) - [👥 Authors](#authors) - [🔭 Future Features](#future-features) - [🤝 Contributing](#contributing) - [⭐️ Show your support](#support) - [🙏 Acknowledgements](#acknowledgements) -- [❓ FAQ](#faq) - [📝 License](#license) -# 📖 [your_project_name] - -> Describe your project in 1 or 2 sentences. +# 📖 Vet Clinic Database -**[your_project__name]** is a... +**Veterinary Clinic Database** Kepp track of the services of a veterinarian, and facilities for the medical treatment, examination, surgery, diagnosis, grooming, general health care, and observation of domestic animals and birds. ## 🛠 Built With ### Tech Stack -> Describe the tech stack and include only the relevant sections that apply to your project. - -
- Client - -
-
- Server + Database
-
-Database - -
### Key Features -> Describe between 1-3 key features of the application. +- Create Database called **Vet Clinic** to store animals records +- Create Table called **animals** and insert records into table +- Make queries to fetch animals records +- Screenshot the queries output, saved it in new folder -- **[key_feature_1]** -- **[key_feature_2]** -- **[key_feature_3]**

(back to top)

- - -## 🚀 Live Demo - -> Add a link to your deployed project. - -- [Live Demo Link]() - -

(back to top)

## 💻 Getting Started -> Describe how a new developer could make use of your project. - To get a local copy up and running, follow these steps. ### Prerequisites - In order to run this project you need: - - +- Basic Knowledge of [DBMS (Database Management System)](https://www.youtube.com/watch?v=mqprM5YUdpk) +- Basic Knowledge of [Relational Database](https://www.youtube.com/watch?v=NvrpuBAMddw) +- Basic Knowledge of [SQL Command](https://www.w3schools.com/sql/default.asp) +- Basic Knowledge of [Postgresql Command](https://www.geeksforgeeks.org/postgresql-psql-commands/) ### Setup - Clone this repository to your desired folder: - - - -### Install - -Install this project with: - - - -### Usage - -To run the project, execute the following command: - - - -### Run tests - -To run tests, run the following command: - - - -### Deployment - -You can deploy this project using: - - +- Postgresql [Installation](https://www.postgresqltutorial.com/postgresql-getting-started/install-postgresql/) on Window +- Postgresql [Installation](https://www.postgresqltutorial.com/postgresql-getting-started/install-postgresql-macos/) on MacOS +- Postgresql [Installation](https://www.postgresqltutorial.com/postgresql-getting-started/install-postgresql-linux/) on Linux

(back to top)

+ ## 👥 Authors -> Mention all of the collaborators of this project. -👤 **Author1** +👤 **Ajayi Ridwan** -- GitHub: [@githubhandle](https://github.com/githubhandle) -- Twitter: [@twitterhandle](https://twitter.com/twitterhandle) -- LinkedIn: [LinkedIn](https://linkedin.com/in/linkedinhandle) - -👤 **Author2** - -- GitHub: [@githubhandle](https://github.com/githubhandle) -- Twitter: [@twitterhandle](https://twitter.com/twitterhandle) -- LinkedIn: [LinkedIn](https://linkedin.com/in/linkedinhandle) +- GitHub: [@Ridwanullahi-code](https://github.com/Ridwanullahi-code) +- Twitter: [@Ridwanullahi22](https://twitter.com/twitterhandle) +- LinkedIn: [LinkedIn](https://www.linkedin.com/in/ajayi-ridwan/)

(back to top)

@@ -226,11 +97,10 @@ Example: ## 🔭 Future Features -> Describe 1 - 3 features you will add to the project. -- [ ] **[new_feature_1]** -- [ ] **[new_feature_2]** -- [ ] **[new_feature_3]** +- **Create examination, surgery, diagnosis tables** +- **Add more records to the tables** +- **Add some constraints to tables**

(back to top)

@@ -240,7 +110,7 @@ Example: Contributions, issues, and feature requests are welcome! -Feel free to check the [issues page](../../issues/). +Feel free to check the [issues page](https://github.com/Ridwanullahi-code/vet_clinic_database/issues)

(back to top)

@@ -248,9 +118,7 @@ Feel free to check the [issues page](../../issues/). ## ⭐️ Show your support -> Write a message to encourage readers to support your project - -If you like this project... +Give a ⭐️ if you like this project!

(back to top)

@@ -258,25 +126,7 @@ If you like this project... ## 🙏 Acknowledgments -> Give credit to everyone who inspired your codebase. - -I would like to thank... - -

(back to top)

- - - -## ❓ FAQ - -> Add at least 2 questions new developers would ask when they decide to use your project. - -- **[Question_1]** - - - [Answer_1] - -- **[Question_2]** - - - [Answer_2] +- Thanks [Microverse](https://microverse.org) for the material you have provided during database creation.

(back to top)

@@ -286,6 +136,4 @@ I would like to thank... This project is [MIT](./LICENSE) licensed. -_NOTE: we recommend using the [MIT license](https://choosealicense.com/licenses/mit/) - you can set it up quickly by [using templates available on GitHub](https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/adding-a-license-to-a-repository). You can also use [any other license](https://choosealicense.com/licenses/) if you wish._ -

(back to top)

diff --git a/data.sql b/data.sql index d818282..a1ac3e4 100644 --- a/data.sql +++ b/data.sql @@ -1,10 +1,25 @@ SET datestyle = dmy; -INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg) -VALUES(1, 'Agumon','02/03/2020',0,true,10.23); -INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg) -VALUES(2, 'Gabumon','15/11/2018',2,true,8.0); -INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg) -VALUES(3, 'Pikachu','07/01/2021',1,false,15.04); -INSERT INTO animals(id, name, date_of_birth, escape_attempts, neutered, weight_kg) -VALUES(4, 'Devimon','12/05/2017',5,true,11.0); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Agumon','02/03/2020',0,true,10.23); + +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Gabumon','15/11/2018',2,true,8.0); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Pikachu','07/01/2021',1,false,15.04); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Devimon','12/05/2017',5,true,11.0); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Charmander','08/02/2020',0,false,-11.0); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Plantmon','15/11/2021',2,true,-5.7); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Squirtle','02/04/1993',3,false,-12.13); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Angemon','12/06/2005',1,true,-45.0); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Boarmon','07/06/2005',7,true,20.4); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Blossom','13/10/1998',3,true,17.0); +INSERT INTO animals(name, date_of_birth, escape_attempts, neutered, weight_kg) +VALUES('Ditto','14/05/2022',4,true,22.0); \ No newline at end of file diff --git a/queries.sql b/queries.sql index f0c1a69..5135d36 100644 --- a/queries.sql +++ b/queries.sql @@ -24,4 +24,48 @@ SELECT * FROM animals WHERE name != 'Gabumon'; SELECT * FROM animals -WHERE weight_kg >= 10.4 AND weight_kg <= 17.3 \ No newline at end of file +WHERE weight_kg >= 10.4 AND weight_kg <= 17.3 + +-- queries to perform transaction + +BEGIN; +UPDATE animals SET species = 'unspecified'; +ROLLBACK; + +BEGIN; +UPDATE animals SET species = 'digimon' WHERE name like '%mon'; +UPDATE animals SET species = 'pokemon'WHERE species is null; +COMMIT; + +BEGIN; +DELETE FROM animals; +ROLLBACK; + +BEGIN; +SAVEPOINT SAVEp1; +DELETE FROM animals WHERE date_of_birth > '2022-01-01'; + +SAVEPOINT SAVEp2; +UPDATE animals SET weight_kg = weight_kg * -1; +ROLLBACK TO SAVEp2; +UPDATE animals SET weight_kg = weight_kg * -1 WHERE weight_kg < 0; +COMMIT; +SELECT * FROM animals; + +-- queries to perform aggregate functions + +SELECT COUNT(*) FROM animals; + +SELECT COUNT(*) FROM animals WHERE escape_attempts = 0; + +SELECT AVG(weight_kg) FROM animals + +SELECT neutered, MAX(escape_attempts) FROM animals +WHERE escape_attempts != 0 +GROUP BY(neutered) + +SELECT MIN(weight_kg), MAX(weight_kg) FROM animals GROUP BY(species); + +SELECT ROUND(AVG(escape_attempts),2) AS average FROM animals +WHERE EXTRACT(YEAR FROM date_of_birth) BETWEEN '1990' AND '2000' +GROUP BY(species) ORDER BY average; \ No newline at end of file diff --git a/schema.sql b/schema.sql index b209dde..f755021 100644 --- a/schema.sql +++ b/schema.sql @@ -1,9 +1,12 @@ /* Database schema to keep the structure of entire database. */ CREATE TABLE animals( - id INTEGER NOT NULL PRIMARY KEY, + id SERIAL NOT NULL PRIMARY KEY, name VARCHAR(255) NOT NULL, date_of_birth DATE NOT NULL, escape_attempts integer NOT NULL, neutered BOOLEAN NOT NULL, weight_kg FLOAT NOT NULL -); \ No newline at end of file +); + +ALTER TABLE animals +ADD COLUMN species VARCHAR(255); \ No newline at end of file