SQL Practice Exercise: Online Mall Database Product Category Data Operation

SQL Practice Exercise: Online Mall Database Product Category Data Operation

Online shopping mall database-product category data operation (I)

Project Description

In the context of the rise of e-commerce, establishing an information portal that uses the Internet to open up sales channels, help companies adjust their product structure in a timely manner, and assist dealers in opening up sources of goods has become an effective solution to the problem of poor information flow. E-commerce is conducive to companies transforming their operating mechanisms, establishing a modern enterprise system, and improving their sales level and competitiveness. It has realized a series of online shopping services such as directly browsing products, purchasing products, creating orders, viewing various new products, special products, hot-selling products, leaving messages, customer management, product management, product information search, order management, product classification management, announcement/feedback management, etc. This project is to realize the operation of the online mall user information form.

The online mall system database operation requirements are as follows:

1) Database EshopDB.

2) Product category parent table EPType, the table structure is shown in Table J2-40-1.

Table J2-40-1 EPType Table

Field Name Field Description Data Types Allow to be empty Remark
EPTID Category ID int no Primary Key
EPTName Category Name Characters(50) no

3) EPType basic data, as shown in Table J2-40-2.

Table J2-13-2 EPType table basic data

EPTID EPTName
1 Jacket
2 hat
3 Children's Wear

4) Commodity category subtable ECType, the table structure is shown in Table J2-40-3.

Table J2-40-3 ECType Table

Field Name Field Description Data Types Allow to be empty Remark
ECTID Category ID int no Primary Key
EPTID Parent Category ID Int no Foreign key, refer to EPType table
ECTName Category Name Characters(50) no

5) Table ECType basic data, as shown in Table J2-40-4.

Table J2-40-4 ECType table basic data

ECTID EPTID ECTName
1 1 shirt
2 1 Sportswear
3 1 coat
4 2 Warm hat
5 2 Sports caps
6 3 Boys
7 3 Girls

(1) Task Description

**Task 1:**Create an online shopping mall database using SQL language

1) Create the database EshopDB and determine whether there is a database with the same name in the system. If so, delete it; if not, create it.

2) The initial value of the main database file is 10MB, the maximum is 30MB, and it increases by 15%.

3) The initial value of the log file is 5MB, the maximum value is 20MB, and it grows automatically.

IF DB_ID('EshopDB') IS NOT NULL DROP DATABASE EshopDB
GO
CREATE DATABASE EshopDB
ON PRIMARY
(
	NAME=EshopDB,
	FILENAME='D:\xxxx\EshopDB.mdf',
	SIZE=10MB,
	MAXSIZE=30MB,
	FILEGROWTH=15%
)
LOG ON
(
	NAME=EshopDB_log,
	FILENAME = 'D:\xxxx\EshopDB_log.ldf',
	SIZE=5MB,
	MAXSIZE=20MB
)

**Task 2:**Use SQL to create the product category parent table EPType and product category child table ECType

1) Create database tables according to the provided table J2-40-1 and table J2-40-3 structures, and set primary keys and foreign keys.

CREATE TABLE EPType
(
	EPTID INT NOT NULL PRIMARY KEY,
	EPTName NVARCHAR(50) NOT NULL,
)

CREATE TABLE ECType
(
	ECTID INT NOT NULL PRIMARY KEY,
	EPTID INT NOT NULL,
	ECTName NVARCHAR(50) NOT NULL,
	FOREIGN KEY(EPTID) REFERENCES EPType(EPTID)
)

**Task 3: **Use SQL language to operate on the product category parent table EPType and the product category child table ECType

1) Create a view to display the sub-category records under the Hats category.

2) Insert records of women's leather shoes, men's sports shoes, and children's shoes into the commodity category sub-table ECType to complete the records of shoes in the commodity category parent table EPType.

3) Count the total number of product subcategories.

INSERT INTO EPType VALUES(1,'Tops'),(2,'Hat'),(3,'Children's Clothing')
INSERT INTO ECType VALUES(1,1,'shirt'),(2,1,'sportswear'),(3,1,'jacket'),(4,2,'warm hat'),(5,2,'sports hat'),(6,3,'boy'),(7,3,'girl')

CREATE VIEW HAT
AS 
SELECT EPType.EPTName,ECType.ECTName 
FROM EPType,ECType 
WHERE ECType.EPTID=(SELECT EPTID FROM EPType WHERE EPType.EPTName='hat') AND EPType.EPTName='hat'
GO
SELECT * FROM HAT

INSERT INTO EPType VALUES(4,'shoes')
INSERT INTO ECType VALUES(8,4,'Women's leather shoes'),(9,4,'Men's sports shoes'),(10,4,'Children's shoes')

SELECT COUNT(*) FROM ECType

This is the end of this article about SQL practical exercises on online shopping mall database product category data operations. For more relevant SQL product category data operations, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • SQL Practice Exercise: Online Mall Database User Information Data Operation
  • Rounding operation of datetime field in MySQL
  • MySQL learning database operation DML detailed explanation for beginners
  • MySQL learning to create and operate databases and table DDL for beginners
  • Detailed explanation of the mysql database LIKE operator in python

<<:  Typora code block color matching and title serial number implementation code

>>:  Tutorial on how to install and use Ceph distributed software under Linux

Recommend

Vue network request scheme native network request and js network request library

1. Native network request 1. XMLHttpRequest (w3c ...

How to implement parent-child component communication with Vue

Table of contents 1. Relationship between parent ...

Specific steps for Vue browser to return monitoring

Preface When sharing a page, you hope to click th...

Analyze several common solutions to MySQL exceptions

Table of contents Preface 1. The database name or...

The difference between Input's size and maxlength attributes

I recently used the input size and maxlength attri...

JavaScript anti-shake and throttling explained

Table of contents Stabilization Throttling Summar...

React encapsulates the global bullet box method

This article example shares the specific code of ...

How to find identical files in Linux

As the computer is used, a lot of garbage will be...

Summary of some common configurations and techniques of Nginx

Preface This article lists several common, practi...

How to monitor multiple JVM processes in Zabbix

1. Scenario description: Our environment uses mic...

Using js to realize dynamic background

This article example shares the specific code of ...