Database Design Guide (1)
Database Design Guide (1)
This guide will help the student to create a database on the Ecommerce System. It will
help to manage the below functionalities.
● Product Details
● Order Details
● Customer Details
We will use MySQL as the DBMS to create the database and its related operations.
1. Introduction to MySQL
MySQL is an open-source relational database management system (RDBMS) that uses
structured query language (SQL) to manage and manipulate data in a database. It is
widely used for various applications, from small web applications to large enterprise
systems.
2. Installation of MySQL
MySQL can be installed on various operating systems, including Windows, macOS, and
Linux. Here are the general steps to install MySQL:
Windows:
● Download the MySQL installer from the official website.
https://dev.mysql.com/downloads/installer/
● Run the installer and follow the on-screen instructions.
● Choose the installation type (Typical, Complete, or Custom). Recommended
Custom.
● Set a root password for the MySQL server.
Identify Entities
● Start by identifying the main entities in your system. These are the objects or
concepts about which you want to store data.
● Each entity should correspond to a table in your database.
Define Attributes
● For each entity, list the attributes (properties or fields) that describe it.
● These attributes will become columns in the corresponding database table.
Identify Relationships
● Determine how entities are related to each other. There are three types of
relationships: one-to-one (1:1), one-to-many (1:N), and many-to-many (N:M).
● Represent these relationships using lines connecting the entities.
One to Many
Many to One
Many to Many
Cardinality Notation
Cardinality represents the number of times an entity of an entity set participates in a
relationship set. Or we can say that the cardinality of a relationship is the number of
tuples (rows) in a relationship.
● Use notation (such as Crow's Foot Notation or Chen Notation) to indicate the
cardinality of each relationship.
● Cardinality describes how many instances of one entity are related to how many
instances of another entity.
● Common notations include:
★ One (1)
★ Zero or one (0..1)
★ Many (N)
★ Zero or many (0..N)
Optional:
Add Attributes and Constraints
● Include additional information in your ERD, such as primary keys, foreign keys,
and constraints (e.g., unique constraints).
1.Product:The first Table is Product which Stores information about the products
available in the eCommerce store, including details like product name, category,
original_price, stock quantity, sub_category.
3.Customer: The customer table contains details about the customers, such as their
name, email etc.
*** Now let’s identify the attributes and relationships of each entity for the Ecommerce
System.
product
● Attributes:
Product_id
Product_name
Category
Sub_category
Original_price
Stock
● Relationships:
One Order_details can book many Product(One-To-Many)
Customer
● Attributes:
customer_id
name
city
email
phone_no
Address
pin_code
● Relationships:
One customer can place many order(One-to-many)
Order_Details
● Attributes:
order_id
customer_id(Foreign key)
product_id(Foreign key)
quantity
total_price
payment_mode
Order_date
order_status
● Relationships:
Many Orders can be placed by one Customer(Many-to-One)
Many Orders can book one Product(Many-to-One)
Table Structure
1.Product Table
2. Customer Table
3.Order_Details Table
Now, let’s create the ER diagram to visually represent the entities and relationships.
ERD Diagram
4. Creating a Database
Using MySQL server, create a new database for your Ecommerce system. You can do
this with SQL commands or through the graphical interface.
5. Using a Database
Before performing any operations on a database, you need to select it using the USE
statement:
USE ecommerce;
7. Insert records
Add data to your tables to work with. This step helps you test your database.
insert into
product(product_id,product_name,category,sub_category,original_price,selling_price,sto
ck) values('P101','Television','Electronics','phone',70000,55000,100),
('P102','Chair','furniture','Chairs',20000,15000,10);
insert into
order_details(customer_id,product_id,quantity,total_price,payment_mode,order_date,or
der_status)values(
'C1002','P101',1,55000,'COD','2023-11-19','shipped'),
('C1001','P101',1,55000,'COD','2023-10-30','delivered');
8. Select records
Write SQL queries to retrieve and manage data.
For example:
9. Update records
PN: Ideally no data should be deleted from any tables. You can use an additional
column to set the status of that record to ‘Active/Inactive’, etc. Or you can use an
Archive table to move the unnecessary records out of the main table.