0% found this document useful (0 votes)
8 views

Database Design Guide (1)

This guide provides a comprehensive overview of creating a database for an Ecommerce System using MySQL, covering essential functionalities such as managing product, order, and customer details. It includes instructions on MySQL installation, designing an Entity-Relationship Diagram (ERD), creating tables, and performing basic SQL operations like inserting, selecting, updating, and deleting records. The document emphasizes the importance of defining entities, attributes, and relationships to effectively structure the database.

Uploaded by

Saurabh Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Database Design Guide (1)

This guide provides a comprehensive overview of creating a database for an Ecommerce System using MySQL, covering essential functionalities such as managing product, order, and customer details. It includes instructions on MySQL installation, designing an Entity-Relationship Diagram (ERD), creating tables, and performing basic SQL operations like inserting, selecting, updating, and deleting records. The document emphasizes the importance of defining entities, attributes, and relationships to effectively structure the database.

Uploaded by

Saurabh Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Database Design Guide

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.

MySQL's key features include:


● Scalability: Capable of handling large amounts of data and concurrent
connections.
● Flexibility: Supports various data types and storage engines.
● Performance: Optimized for speed and efficiency.
● Reliability: Known for its stability and robustness.

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.

3. E-R Diagram (ERD)


An Entity-Relationship Diagram (ERD) is a visual representation of the data model that
shows the entities, attributes, relationships between entities, and cardinality. ERDs are
commonly used in database design to help developers and stakeholders understand the
structure and relationships within a database.

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.

Let’s see a few examples of relationships:


One to One

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).

Create the Diagram


● Use specialized diagramming software or tools (e.g., Lucidchart, draw.io, or even
pen and paper) to create your ERD.

Refine and Review:


● Review your ERD with stakeholders and team members to ensure it accurately
represents the data model and relationships. Make any necessary refinements.

Let’s Discuss about Ecommerce Project:

An SQL-based e-commerce project involves designing and implementing a relational


database to store and manage various aspects of an online store, such as products,
customers, orders, and inventory.

Designing an Ecommerce Database

Let’s identify the entities of the Ecommerce system:

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.

2.Order Details: Keeps track of customer orders, including total_price,payment


mode,order date,order status etc.

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.

CREATE DATABASE ecommerce;

5. Using a Database
Before performing any operations on a database, you need to select it using the USE
statement:

USE ecommerce;

6. Creating the tables for each entity


USE ecommerce;

CREATE TABLE product (


product_id varchar(10) NOT NULL primary key,
product_name varchar(100) NOT NULL,
category varchar(65) NOT NULL,
sub_category varchar(45) NOT NULL,
original_price double NOT NULL,
selling_price double NOT NULL,
stock int NOT NULL
);

CREATE TABLE customer (


customer_id varchar(10) NOT NULL primary key,
name varchar(100) NOT NULL,
city varchar(65) NOT NULL,
email varchar(45) NOT NULL,
phone_no varchar(15) NOT NULL,
address varchar(100) NOT NULL,
pin_code int NOT NULL
);

CREATE TABLE order_details (


order_id int(11) NOT NULL primary key auto_increment,
customer_id varchar(10) NOT NULL,
product_id varchar(10) NOT NULL,
quantity double NOT NULL,
total_price double NOT NULL,
payment_mode varchar(60) NOT NULL,
order_date DateTime NOT NULL,
order_status varchar(20) NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customer(customer_id),
FOREIGN KEY (product_id) REFERENCES product(product_id)
);

7. Insert records
Add data to your tables to work with. This step helps you test your database.

Insert in Product Table

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 in Customer Table

insert into customer(customer_id,name,city,email,phone_no,address,pin_code) values


('C1001','Steve','Tokyo','[email protected]','4567897652','f.g.road', 100-0001),
('C1002','john','Sydney','[email protected]','9987234567','k.c.road', 75001);

Insert in order_details table

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:

Retrieve all customer:

Select * FROM customer;

*Now try similar Select queries with other tables

9. Update records

Write SQL statements to update record(s) when needed. For example:

Update a customer's email:

update customer SET email='[email protected]' where customer_id='C1002';

10. Delete records

Write SQL statements to delete record(s) when needed.

delete from customer where customer_id='C1002';

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.

You might also like