SQL实战演练之网上商城数据库商品类别数据操作

网上商城数据库-商品类别数据操作(一)

项目描述

在电子商务兴起的大环境下,建立利用互联网开拓销售渠道,帮助企业及时调整商品结构,协助经销商打开货源的信息门户成为解决信息流通不畅的有效方案,电子商务有利于企业转换经营机制,建立现代企业制度,提高企业的销售水平和竞争力,实现了在网上直接浏览商品、购买商品、创建订单、查看各类新品、特价商品、热销商品等,留言、客户管理、商品管理、商品资料搜索、订单管理、商品分类管理、公告/反馈管理等一系列的网上购物服务,本项目就是实现网上商城用户信息表格的操作。

网上商城系统数据库操作要求如下:

1)数据库eshopdb。

2)商品类别父表eptype,表结构如表j2-40-1所示。

表j2-40-1 eptype表

字段名 字段说明 数据类型 允许为空 备注
eptid 类别id int 主键
eptname 类别名称 字符(50)

3)eptype基础数据,如表j2-40-2所示。

表j2-13-2 eptype表基础数据

eptid eptname
1 上衣
2 帽子
3 童装

4)商品类别子表ectype,表结构如表j2-40-3所示。

表j2-40-3 ectype表

字段名 字段说明 数据类型 允许为空 备注
ectid 类别id int 主键
eptid 父类别id int 外键,参照eptype表
ectname 类别名称 字符(50)

5)表ectype基础数据,如表j2-40-4所示。

表j2-40-4 ectype表基础数据

ectid eptid ectname
1 1 衬衣
2 1 运动装
3 1 外套
4 2 保暖帽
5 2 运动帽
6 3 男童
7 3 女童

(1)任务描述

**任务1:**用sql语言创建网上商城数据库

1)创建数据库eshopdb,判断系统中是否有该名字的数据库,如果有则删除;如果没有则创建该数据库。

2)主数据库文件初始值10mb,最大30mb,按15%进行递增。

3)日志文件初始值为5mb,最大为20mb,自动增长。

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
)

**任务2:**用sql语言创建商品类别父表eptype、 商品类别子表ectype

1)按照提供的表表j2-40-1、表j2-40-3结构创建数据库表,并设主键和外键。

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

**任务3:**用sql语言对商品类别父表eptype、 商品类别子表ectype进行操作

1)创建视图显示帽子类别的下的子类别记录。

2)在商品类别子表ectype中插入女皮鞋、男运动鞋、童鞋记录,完善商品类别父表eptype鞋类记录。

3)统计出总共有多少商品子类别。

insert into eptype values(1,'上衣'),(2,'帽子'),(3,'童装')
insert into ectype values(1,1,'衬衣'),(2,1,'运动装'),(3,1,'外套'),(4,2,'保暖帽'),(5,2,'运动帽'),(6,3,'男童'),(7,3,'女童')

create view  hat
as 
select eptype.eptname,ectype.ectname 
from eptype,ectype 
where ectype.eptid=(select eptid from eptype where eptype.eptname='帽子') and eptype.eptname='帽子'
go
select * from hat

insert into eptype values(4,'鞋')
insert into ectype values(8,4,'女皮鞋'),(9,4,'男运动鞋'),(10,4,'童鞋')

select count(*) from ectype

到此这篇关于sql实战演练之网上商城数据库商品类别数据操作的文章就介绍到这了,更多相关sql 商品类别数据操作内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐