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

In-depth analysis of MySQL database transactions and locks

Table of contents 1. Basic Concepts ACID 3.AutoCo...

HTML code to add quantity badge to message button

HTML code: <a onclick="goMessage();"...

Detailed explanation of four solutions to floating problems in CSS layout

1. Cause: The effect after the subbox is set to f...

Windows Server 2008 Tutorial on Monitoring Server Performance

Next, we will learn how to monitor server perform...

Mysql sql slow query monitoring script code example

1. Modify my.cnf #The overall effect is that both...

Some lesser-known sorting methods in MySQL

Preface ORDER BY 字段名升序/降序, I believe that everyon...

Bugs encountered when using mybatis-generator with mysql8.0.3 in IDEA

1. Add the plug-in and add the following configur...

React hooks pros and cons

Table of contents Preface advantage: shortcoming:...

Methods for deploying MySQL services in Docker and the pitfalls encountered

I have been learning porters recently. I feel lik...

Install and build a server environment of PHP+Apache+MySQL on CentOS

Yum (full name Yellow dog Updater, Modified) is a...

Configure VIM as a C++ development editor in Ubuntu

1. Copy the configuration file to the user enviro...

Detailed explanation of the steps to build a Vue project with Vue-cli

First you need to install Vue-cli: npm install -g...

Basic syntax of MySQL index

An index is a sorted data structure! The fields t...

MySQL sharding details

1. Business scenario introduction Suppose there i...

Usage and best practice guide for watch in Vue3

Table of contents Preface🌟 1. API Introduction 2....