Create Database ProductDB
on Primary
(name=' ProductDB',
filename='D:\boss\ ProductDB.mdf')
log on
(name='ProductDB_log',
filename='D:\boss\ ProductDB_log.ldf')
use ProductDB
go
Create table T_category
(
Category_id int identity(1,1),
Category_name character(100),
Register_date date,
primary key(Category_id )
)
Create table T_product
(
Product_id int identity(1,1),
Category_id int,
Product_name char(50),
Price money,
Remark character(50),
Register_date date,
primary key(Product_id )
)
Create table T_product_review
(
Review_id int identity(1,1),
Product_id int,
Review character(100),
Register_date date,
primary key(Review_id),
)
alter table T_product
add constraint FK_T_product_Category_id foreign key(Category_id ) references T_category(Category_id )
alter table T_product_review
add constraint FK_T_product_review_Product_id foreign key(Product_id ) references T_product(Product_id )
--产品价格列(Price)只能输入 1-500 之间的数;--
alter table T_product
add constraint CK_T_product_price check(price>0 and price<501)
--在三个表中分别录入 3 条测试数据(样本数据包含下面题目中使用的数据);--
insert into T_category values('军用','2011-3-6')
insert into T_category values('民用','2011-4-6')
insert into T_category values('医用','2011-2-6')
insert into T_product values('1','军刀','400','用于军用','2011-3-6')
insert into T_product values('2','杀虫剂','132','用于杀虫','2011-5-2')
insert into T_product values('3','口罩','20','用于手术','2011-3-6')
insert into T_product_review values('1','质量好','2011-4-3')
insert into T_product_review values('2','药效强','2011-6-4')
insert into T_product_review values('3','软','2011-5-3')
--查询某类别下评论数超过 3 条的所有产品的名称;--
select [Review_id] from [dbo].[T_product_review] where [Review_id]>2
--查询产品价格超过 400 元的所有产品;--
select [Product_name] from [dbo].[T_product] where [Price] >=400
--创建名为 product_view1 的视图,视图中的数据包括录入日期在 2011 年 3 月到 6 月之间的产品数据信息;--
go
create view product_view1
as
select*from[dbo].[T_product] where[register_date] between '2011-3-1' and '2011-6-30'
--删除上题中所创建的视图 product_view1;--
go
select*from product_view1
drop view product_view1
--充值金额列(the_money)只能输入 50-200 之间的数;--
delete from[dbo].[T_category] [dbo].[T_product_review] [dbo].[T_product] where
T_category.Category_id=[dbo].[T_product].Category_id and [dbo].[T_product].[Product_id]=[dbo].[T_product_review].[Product_id]
Price>=400
2-3 《某电子商务网站》评论管理模块
最新推荐文章于 2023-05-29 14:05:41 发布