Stored procedures may help store the SQL code, which can be reused by different applications for performing calculations on the database server. In this task, you will work with the new version of a ShopDB
database for online store with the following tables:
Countries
, which has the following columns:ID
andName
.Products
, which has the following columns:ID
andName
.Warehouses
, which has the following columns:ID
,Name
,Address
, andCountryID
.ProductInventory
, which has the following columns:ID
,ProductID
,WarehouseAmount
, andWarehouseID
.
- Install and configure a MySQL database server on a Virtual Machine and connect to it with the MySQL client.
- Fork this repository.
Develop a stored procedure, which will show the information about a warehouse's product amount. For that, you need to write the SQL code in the task.sql
file:
- Connect to your database server.
- If you already have the
ShopDB
database on your database server from the previous tasks, delete it using theDROP DATABASE ShopDB;
statement. - Write a code for the stored procedure creation in the
task.sql
file.
The stored procedure should meet the following requirements:
- It should be called
get_warehouse_product_inventory
. - It should accept a single parameter — ID of the Warehouse.
- It should return a table with a list of product names, along with their amount in the warehouse.
Hint
Use the SELECT
statement with JOIN
in the stored procedure body.
Just in case you want to test your script on your database before submitting a pull request, you can do it by performing the following actions:
- Drop the
ShopDB
database using theDROP DATABASE ShopDB;
statement if you already have it on your database server. - Run the database creation script (
create-database.sql
) on your database server. - Run the script you wrote in the
task.sql
on your database server. - Run the
test.sql
script on your database. If the script execution is finished without errors and if in the output you are getting only 1 item (AwersomeProduct
, count —4242
) you are ready to submit a pull request.