This project involves creating a set of database tables using Data Definition Language (DDL) for a small e-commerce system. The tables include Customers, Products, Categories, Orders, and OrderDetails. Each table is designed to support key relationships with foreign keys, ensuring data integrity between the tables.
-
Customers Table
I created a table namedCustomerswhich stores customer information such as customer ID, name, and other relevant details. -
Categories Table
TheCategoriestable stores product categories. This table includes a primary keyCategory_Id, which is referenced by theProductstable. -
Products Table
TheProductstable stores product information. It has a foreign keyCategory_Id, which references theCategory_Idfrom theCategoriestable to establish a relationship between products and their respective categories. -
Orders Table
TheOrderstable stores order information. It has a foreign keyCustomer_Idthat references theCustomer_Idfrom theCustomerstable, establishing the relationship between a customer and their orders. -
OrderDetails Table
TheOrderDetailstable stores detailed information about individual products within an order. It includes two foreign keys:Order_Id, which references theOrder_Idfrom theOrderstable.Product_Id, which references theProduct_Idfrom theProductstable.
After creating the tables, I wrote SQL code to retrieve data from each of the tables using SELECT queries. These queries fetch data from Customers, Categories, Products, Orders, and OrderDetails in sequence.
-
Created Tables:
- Customers
- Categories
- Products (with foreign key
Category_Id) - Orders (with foreign key
Customer_Id) - OrderDetails (with foreign keys
Order_IdandProduct_Id)
-
Executed SQL Queries:
- Selected data from each table (
Customers,Categories,Products,Orders,OrderDetails).
- Selected data from each table (
This DDL checkpoint exercise successfully demonstrates the creation of tables and relationships using foreign keys, ensuring referential integrity in a relational database structure.
##DML CHECKPOINT
The objective of this project is to implement SQL Data Manipulation Language (DML) queries to manage records within the database tables defined in the Fleet Management schema. The SQL code provided covers the creation of the required tables, insertion of sample data, and updating, deleting, and querying of records.
Before running the SQL code, ensure you have the following:
- SQL Database Environment: A running instance of an SQL database like MySQL, PostgreSQL, or SQL Server.
- SQL Client Tool: An SQL client like MySQL Workbench, pgAdmin, or any terminal-based SQL command-line tool.
- Access Rights: Administrator or required privileges to create tables and insert data into the database.
-
Open SQL Client: Launch your preferred SQL client (such as MySQL Workbench or pgAdmin), connect to your database, and open a new SQL query window.
-
Create the Database (Optional): If you don't have a database created for the project, you can create one by running:
CREATE DATABASE FleetManagement; USE FleetManagement;