-1-昆明理工大学信息工程与自动化学院学生实验报告(2014—2015学年第1学期)课程名称:数据库仓库与数据挖掘开课实验室:信自楼4442014年12月28日年级、专业、班计科111学号201110405138姓名成绩实验项目名称数据仓库的建立指导教师周海河教师评语该同学是否了解实验原理:A.了解□B.基本了解□C.不了解□该同学的实验能力:A.强□B.中等□C.差□该同学的实验是否达到要求:A.达到□B.基本达到□C.未达到□实验报告是否规范:A.规范□B.基本规范□C.不规范□实验过程是否详细记录:A.详细□B.一般□C.没有□教师签名:年月日一、实验内容和目的目的:1.理解数据库与数据仓库之间的区别与联系;2.掌握典型的关系型数据库及其数据仓库系统的工作原理以及应用方法;3.掌握数据仓库建立的基本方法及其相关工具的使用。二、实验原理及基本技术路线图(方框原理图)数据库(DataBase,DB)是长期存储在计算机内、有组织的、统一管理的相关数据的集合。DB能为各种用户共享,具有较小的冗余度、数据间联系紧密而又有较高的数据独立性等特点。构成的三要素是数据结构、数据操作、约束性条件。三、所用仪器、材料(设备名称、型号、规格等)PC机和MicrosoftSQLServer2008四、实验方法、步骤-2-1、登录SQLServer登录名:localhost2、使用SQL语句构建数据库(1)还原数据库-3-(2)建立数据--建立数据USEcdCREATEDATABASE[DW]ONPRIMARY(NAME=N'DW',FILENAME=N'G:\DW.mdf')LOGON(NAME=N'DW_log',FILENAME=N'G:\DW_log.ldf')GO(3)建立数据库:数据库→新建数据库(4)建维表①SQL语句USEDW----------------------------------1、建维表/*1.1订单方式*/CREATETABLEDIM_ORDER_METHOD(ONLINEORDERFLAGINT,DSCVARCHAR(20))/*1.2销售人员及销售地区*/CREATETABLEDIM_SALEPERSON(SALESPERSONIDINT,DSCVARCHAR(20),SALETERRITORY_DSCVARCHAR(50))-4-/*1.3发货方式*/CREATETABLEDIM_SHIPMETHOD(SHIPMETHODIDINT,DSCVARCHAR(20))/*1.4订单日期*/CREATETABLEDIM_DATE(TIME_CDVARCHAR(8),TIME_MONTHVARCHAR(6),TIME_YEARVARCHAR(6),TINE_QUAUTERVARCHAR(8),TIME_WEEKVARCHAR(6),TIME_XUNVARCHAR(4))/*1.5客户*/CREATETABLEDIM_CUSTOMER(CUSTOMERIDINT,CUSTOMER_NAMEVARCHAR(100),CUSTOMERTYPEVARCHAR(20),AGEINT,SEXVARCHAR(2),MaritalStatusVARCHAR(10),YearlyIncomeVARCHAR(50),EducationVARCHAR(50),OccupationVARCHAR(50),NumberCarsOwnedINT,TotalChildrenINT,COUNTRY_NAMEVARCHAR(100),STATEPROVINCE_NAMEVARCHAR(100),CITY_NAMEVARCHAR(100))/*1.6订单状态*/CREATETABLEDIM_ORDER_STATUS(STATUSINT,DSCVARCHAR(30))/*1.7客户价值*/CREATETABLEV_SUBTOTAL_VALUES(ORDER_VALUES_IDINT,DSCVARCHAR(30),MIN_VALUEINT,MAX_VALUEINT)-5-(5)建维度表的ETL①SQL语句--二、维度表的ETL-------------------------------------INSERTINTODIM_ORDER_METHODVALUES(0,'销售人员')INSERTINTODIM_ORDER_METHODVALUES(1,'客户在线')INSERTINTODIM_SHIPMETHODSELECTShipMethodID,NAMEFROMcd.Purchasing.ShipMethodINSERTINTODIM_SALEPERSONSELECTA.SalesPersonID,'',B.NameFROMcd.Sales.SalesPersonA,cd.Sales.SalesTerritoryBWHEREA.TerritoryID=B.TerritoryIDINSERTINTODIM_ORDER_STATUSVALUES(1,'处理中')INSERTINTODIM_ORDER_STATUSVALUES(2,'已批准')INSERTINTODIM_ORDER_STATUSVALUES(3,'预订')INSERTINTODIM_ORDER_STATUSVALUES(4,'已拒绝')INSERTINTODIM_ORDER_STATUSVALUES(5,'已发货')INSERTINTODIM_ORDER_STATUSVALUES(6,'已取消')INSERTINTOV_SUBTOTAL_VALUESVALUES(1,'0-100',0,100)INSERTINTOV_SUBTOTAL_VALUESVALUES(2,'100-500',100,500)INSERTINTOV_SUBTOTAL_VALUESVALUES(3,'500-1000',500,1000)INSERTINTOV_SUBTOTAL_VALUESVALUES(4,'1000-2000',1000,2000)INSERTINTOV_SUBTOTAL_VALUESVALUES(5,'2000-5000',2000,5000)INSERTINTOV_SUBTOTAL_VALUESVALUES(6,'5000以上',5000,1000000000)-6-declare@daydateTIMESET@day='2001-01-01'while@day'2005-01-01'BEGINinsertintoDIM_DATESELECTCONVERT(CHAR(8),@day,112),CONVERT(CHAR(6),@day,112),CONVERT(CHAR(4),@day,112)+'年','第'+CAST(DATEname(QUARTER,@day)ASVARCHAR(1))+'季度',DATEname(weekday,@day),caseWHENDATEPART(DAY,@day)11THEN'上旬'WHENDATEPART(DAY,@day)21THEN'中旬'ELSE'下旬'ENDSELECT@day=DATEADD(DAY,1,@day)ENDINSERTINTODIM_CUSTOMERSELECTA.CustomerID,G.FirstName,CASEWHENA.CustomerType='I'THEN'个人'ELSE'商店'END,DATEDIFF(YEAR,Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:BirthDate)[1]','VARCHAR(10)'),GETDATE()),Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:Gender)[1]','VARCHAR(2)'),Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:MaritalStatus)[1]','VARCHAR(10)'),Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:YearlyIncome)[1]','VARCHAR(20)'),Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:Education)[1]','VARCHAR(20)'),Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:Occupation)[1]','VARCHAR(20)'),Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:NumberCarsOwned)[1]','int'),Demographics.value('declarenamespacezhh=(/zhh:IndividualSurvey/zhh:TotalChildren)[1]','int'),F.Name,E.Name,D.CityFROMcd.Sales.CustomerA,cd.Sales.IndividualB,cd.Sales.CustomerAddressC,cd.Person.AddressD,cd.Person.StateProvinceE,cd.Person.CountryRegionF,cd.Person.ContactGWHEREA.CustomerID=B.CustomerIDANDA.CustomerID=C.CustomerIDANDC.AddressID=D.AddressIDANDD.StateProvinceID=E.StateProvinceIDANDE.CountryRegionCode=F.CountryRegionCodeANDB.ContactID=G.ContactID②执行SQL语句后(6)建事实表--三、建事实表CREATETABLEFACT_SALEORDER(SALEORDERIDINT,TIME_CDVARCHAR(8),S