Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

PostgreSQL Bookstore Database

Overview

This README provides a high-level explanation of how I created a PostgreSQL database to simulate a basic bookstore. The database design focuses on managing books, authors, customers, and transactions, enabling essential operations like adding, updating, and retrieving data.

Setup Instructions

Install PostgreSQL: Ensure PostgreSQL is installed on your system. You can download it from the official website.

Create the Database:

Launch psql or your preferred PostgreSQL client.

Create a new database for the bookstore using:

CREATE DATABASE bookstore;

Connect to the newly created database:

\c bookstore

Database Structure

The bookstore database consists of multiple interconnected tables. These include:

Books Table:

Stores information about each book, such as title, genre, price, and stock quantity.

Authors Table:

Contains details about authors, including their names and biographies.

Customers Table:

Records customer information, like names, emails, and contact details.

Orders Table:

Tracks purchases made by customers, including the date and total amount.

Order_Details Table:

Links orders to specific books, detailing quantities and individual prices.

Basic Queries

  1. Inserting Data:

Insert new records into the tables to populate the database with books, authors, and customers.

INSERT INTO books (title, genre, price, stock_quantity) VALUES ('Sample Book', 'Fiction', 19.99, 100);

  1. Retrieving Data:

Fetch information using SELECT queries. For example, to list all available books:

SELECT * FROM books;

  1. Updating Data:

Modify existing records, such as updating stock quantities after a purchase:

UPDATE books SET stock_quantity = stock_quantity - 1 WHERE book_id = 1;

  1. Deleting Data:

Remove records if needed, such as deleting an out-of-stock book:

DELETE FROM books WHERE stock_quantity = 0;

  1. Joining Tables:

Retrieve combined data from multiple tables, like listing all books along with their authors:

SELECT books.title, authors.name FROM books JOIN authors ON books.author_id = authors.author_id;

  1. Aggregating Data:

Perform calculations such as total sales:

SELECT SUM(total_amount) FROM orders;

Additional Notes

Ensure proper indexing for frequently queried columns to enhance performance.

Use constraints and foreign keys to maintain data integrity between tables.

Regularly back up your database to prevent data loss.

Conclusion

This PostgreSQL bookstore database offers a foundational structure for managing a small bookstore's data operations. You can expand it by adding more complex features like user authentication, advanced reporting, and integration with web applications.

About

BookStore DataBase

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors