This project demonstrates core relational database and SQL skills. It involves designing a PostgreSQL database from the ground up using an Entity Relationship Diagram (ERD) as a blueprint.
Key components include:
Hermione’s Hardware Store is a fictitious business that needs help with setting up a database to track its tool sales and rentals. Currently, the store owners are tracking everything with spreadsheets, but that is becoming cumbersome as business increases. After meeting with the store owners, enough information has been gathered to begin working on their new database system.
The store wants to keep records on a variety of business items and transactions. These include customer, tool, manufacturer, supplier, purchase, rental, and sale information. Tracking these items and transactions will enable the company to analyze different aspects of the business and make informed decisions.
The store owners need the database to adhere to several business rules:
The Entity Relationship Diagram for the hardware store database is shown below. This shows all of the entities, their attributes, primary and foreign keys, and their relationships to each other. A customer can purchase and/or rent tools without having to set up an additional account.
The nine entities, their attributes, and the primary keys are outlined below. These were developed with the business rules and requirements in mind. The primary keys are bolded, and the foreign keys are identified with “FK”.
These are the PostgreSQL statements to create the 9 tables in the database. Each table column is designated with data types and constraints (primary key, foreign key, not null, etc.)
I generated fictitious sample data to populate the tables. For brevity, only the tool table is shown below.
INSERT INTO tool (toolid,toolname,serialno,inventoryqty,usearea,powersystem,
rentalfee,saleprice,purchaseprice)
VALUES
(1001,'Wet/Dry Vacuum',46738,3,'floor','AC',20.00,100.00,60.00),
(1002,'Leaf Blower',938006,3,'lawn & yard','battery',20.00,80.00,70.00),
(1003,'Ladder',77336,5,'general','none',20.00,80.00,50.00),
(1004,'Air Compressor',736559,4,'general','AC',40.00,200.00,150.00),
(1005,'Air Nailer',54321,3,'construction','AC',30.00,120.00,70.00),
(1006,'Carjack',84775,5,'auto','none',10.00,40.00,30.00),
(1007,'Space Heater',457799,6,'general','AC',10.00,50.00,30.00),
(1008,'Push Lawnmower',88473,4,'lawn & yard','fuel',30.00,150.00,120.00),
(1009,'Riding Lawnmower',58844,3,'lawn & yard','fuel',60.00,1000.00,600.00),
(1010,'Chainsaw',837267,3,'lawn & yard','fuel',20.00,100.00,60.00),
(1011,'Carpet Shampoo',63746,6,'floor','AC',20.00,120.00,80.00),
(1012,'Electric Sewer Snake',3009586,3,'plumbing','AC',30.00,100.00,60.00),
(1013,'Manual Drain Cleaner',49586,4,'plumbing','none',10.00,50.00,40.00),
(1014,'Generator',39958,3,'general','fuel',60.00,1000.00,600.00),
(1015,'Table Saw',57687,3,'construction','AC',60.00,800.00,600.00),
(1016,'Drain Camera',56978,2,'plumbing','AC',40.00,500.00,400.00),
(1017,'Paint Sprayer',687934,3,'construction','fuel',30.00,100.00,60.00),
(1018,'Shop Light',396887,4,'general','AC',20.00,100.00,60.00),
(1019,'Garden Hose',45809,3,'lawn & yard','none',10.00,20.00,15.00),
(1020,'Socket Set',30597,5,'general','none',10.00,100.00,60.00);
Once the database structure was created and populated with data, it was ready for querying. The hardware store wants answers to some business questions, so let’s query the database with PostgreSQL!
Hermione’s Hardware Store will benefit significantly from their new database. It enables more efficient data tracking while reducing reliance on spreadsheets. By streamlining operations, the database frees up time for other business priorities and supports data-driven decision-making. Additionally, it adheres to all business rules established by the store owners.