产品方案
本主题详细介绍了 AdventureWorks 示例数据库中的产品信息、一些与产品相关的表的列表以及说明常见表关系的示例查询。
产品概述
作为自行车生产公司,Adventure Works Cycles 提供以下四类产品:
- Adventure Works Cycles 公司生产的自行车。
- 自行车组件(替换零件),例如,车轮、踏板或刹车部件。
- 从供应商购买的转售给 Adventure Works Cycles 客户的自行车装饰。
- 从供应商购买的转售给 Adventure Works Cycles 客户的自行车附件。
产品表
下表简要说明了与产品相关的表中存储的数据。
Schema.Table | 包含以下内容 | 注释 |
---|---|---|
用于制造自行车和自行车子部件的所有组件的列表。 |
ProductAssemblyID 列表示父级产品(即主产品),ComponentID 表示用来组成父级部件的子级零件(即独立零件)。 |
|
列出使用了哪些语言来本地化产品说明。 |
提供了阿拉伯语、英语、法语、希伯来语、简体中文和泰语的产品说明。 |
|
列出 Adventure Works Cycles 中产品和零件的库存位置。例如,油漆既贮藏在仓库的 Paint Storage 处,又储藏在制造中心 Paint Shop(自行车骨架在这里上漆)。 |
|
|
由 Adventure Works Cycles 销售或用来制造 Adventure Works Cycles 自行车和自行车组件的各种产品的信息。 |
FinishedGoodsFlag 列指示产品是否可供出售。不供出售的产品是出售产品的组件。例如,可以出售一辆自行车,但不会出售用于制造自行车的金属材料。 |
|
产品最常规的分类。例如,自行车或附件。 |
|
|
列出不同时间点的产品成本。 |
|
|
列出各种语言的详细产品说明。 |
提供了阿拉伯语、英语、法语、希伯来语、简体中文和泰语的产品说明。 |
|
按地点统计的产品库存量。请参阅前面介绍的 Production.Location。 |
|
|
列出不同时间点的产品价格。 |
|
|
与产品关联的产品型号。例如,Mountain-100 或 LL Touring Frame。 |
CatalogDescription 列包含 xml 数据类型的附加产品信息。Instructions 列通过使用 xml 数据类型给出产品生产说明。 |
|
给出产品型号、产品说明和及其本地化后的语言之间的交叉引用。 |
|
|
列出 Adventure Works Cycles 所售产品的图像。 |
图像是使用 varbinary(max) 数据类型存储的。 |
|
给出客户对 Adventure Works Cycles 产品的评价。 |
|
|
产品类别的子类别。例如,“山地自行车”、“平地自行车”和“旅行登山车”是“自行车”类别的子类别。 |
|
示例
您可以使用下列查询来查看产品数据,并熟悉产品-表关系。
A. 按类别、子类别和型号查看产品
下面的示例按类别、子类别和型号列出了所有产品,不包含没有分类的产品。若要包含所有产品,请将 ProductCategory
上的联接更改为完整联接。
USE AdventureWorks;
GO
SELECT PC.Name AS Category, PSC.Name AS Subcategory,
PM.Name AS Model, P.Name AS Product
FROM Production.Product AS P
FULL JOIN Production.ProductModel AS PM ON PM.ProductModelID = P.ProductModelID
FULL JOIN Production.ProductSubcategory AS PSC ON PSC.ProductSubcategoryID = P.ProductSubcategoryID
JOIN Production.ProductCategory AS PC ON PC.ProductCategoryID = PSC.ProductCategoryID
ORDER BY PC.Name, PSC.Name ;
GO
B. 按产品型号查看产品说明
为每一产品型号提供了多个语言版本的产品说明。下面的示例显示每一产品说明的各个语言版本。
注意: |
---|
除非为复杂脚本和东亚语言安装补充语言支持文件,否则某些语言可能无法正确显示。若要安装上述文件,请参阅有关“区域选项”和“语言选项”的 Windows 文档。 |
USE AdventureWorks;
GO
SELECT PM.ProductModelID, PM.Name AS [Product Model], Description, PL.CultureID, CL.Name AS Language
FROM Production.ProductModel AS PM
JOIN Production.ProductModelProductDescriptionCulture AS PL
ON PM.ProductModelID = PL.ProductModelID
JOIN Production.Culture AS CL ON CL.CultureID = PL.CultureID
JOIN Production.ProductDescription AS PD
ON PD.ProductDescriptionID = PL.ProductDescriptionID
ORDER BY PM.ProductModelID ;
GO
C. 查看父级产品的单个单级别物料清单列表
下面的示例显示用于创建特定父产品的所有组件:ProductAssemblyID
。
USE AdventureWorks;
GO
WITH Parts(AssemblyID, ComponentID, PerAssemblyQty, EndDate, ComponentLevel) AS
(
SELECT b.ProductAssemblyID, b.ComponentID, b.PerAssemblyQty,
b.EndDate, 0 AS ComponentLevel
FROM Production.BillOfMaterials AS b
WHERE b.ProductAssemblyID = 800
AND b.EndDate IS NULL
UNION ALL
SELECT bom.ProductAssemblyID, bom.ComponentID, p.PerAssemblyQty,
bom.EndDate, ComponentLevel + 1
FROM Production.BillOfMaterials AS bom
INNER JOIN Parts AS p
ON bom.ProductAssemblyID = p.ComponentID
AND bom.EndDate IS NULL
)
SELECT AssemblyID, ComponentID, Name, PerAssemblyQty, EndDate,
ComponentLevel
FROM Parts AS p
INNER JOIN Production.Product AS pr
ON p.ComponentID = pr.ProductID
ORDER BY ComponentLevel, AssemblyID, ComponentID;
GO