首页 新闻 会员 周边

动态表的操作

0
悬赏园豆:60 [已关闭问题]

本人最近负责一个项目,这个项目其中商品有如下几类(其中包含很多子类)

电脑HP(笔记本、台式机),组装机(鼠标、键盘、音响、CUP、内存、显卡……) ,外设,投影机 ,音视频,监控等

数据库设计如下:

代码
-- 类别表
create table Category
(
Id
int identity primary key, -- 类别编号
Name varchar(20) not null, -- 类别名称
ParentId int not null -- 父级Id
)
go
insert into Category values('HP电脑',0)
insert into Category values('组装机',0)
insert into Category values('鼠标',2)
go

-- 属性表
create table Property
(
Id
int identity primary key, -- 属性Id
Name varchar(20) not null, -- 属性名称
Type varchar(20) not null, -- 属性类型
Size int not null, -- 属性大小
CategoryId int not null -- 所属分类
)
go
insert into [Property] values('鼠标引擎','string',20,3)
insert into [Property] values('按键数','int',4,3)
insert into [Property] values('鼠标接口','string',10,3)
go

-- 产品表
create table Product
(
Id
int identity primary key, -- 产品编号
Name varchar(20) not null, -- 产品名称
CategoryId int not null -- 所属类别
)
go
insert into Product values('罗技M215无线鼠标',3)
insert into Product values('雷柏V2游戏鼠标',3)
go

-- 产品属性关联表
create table ProductProperty
(
Id
int identity primary key, -- 关联Id
ProductId int not null, -- 产品Id
PropertyId int not null, -- 属性Id
PropertyValue varchar(2000) -- 属性值
)
go
insert into ProductProperty values(1,1,'光电')
insert into ProductProperty values(1,2,'3')
insert into ProductProperty values(1,3,'USB')
insert into ProductProperty values(2,1,'激光')
insert into ProductProperty values(2,2,'9')
insert into ProductProperty values(2,3,'USB')
go

select * from Category
select * from Property
select * from Product
select * from ProductProperty
go

 

我到得到一些结果
比如得到鼠标类型的产品列表

鼠标名称               鼠标引擎 按键数    鼠标接口
-----------------------------------------------
罗技M215无线鼠标 光电       3           USB
雷柏V2游戏鼠标      激光       9           USB

问题补充: 我想得某个类别下的所有产品信息,请大家提供下SQL语句
Fencer的主页 Fencer | 初学一级 | 园豆:7
提问于:2010-06-20 11:43
< >
分享
其他回答(1)
0

你想做什么?

Astar | 园豆:40805 (高人七级) | 2010-06-20 13:19
我提供了SQL,我想得到某种类型的产品列表 如现在要得到鼠标类型的产品列表 写出SQL,性能要好
支持(0) 反对(0) Fencer | 园豆:7 (初学一级) | 2010-06-20 14:24
0
邀月 | 园豆:25475 (高人七级) | 2010-06-20 16:44
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册