MSBI--enlarge the DW database table volume
我们在学习MSBI的时候,经常会使用官方提供的Adventureworks和AdventureworksDW示例数据库,但是官方提供的数据量有点小,
以DW为例,Factinternetsales只有不到七万行的数据,我们很难做某些测试,譬如说想对事实表做一个分区测试,测试CUBE性能等.
为此,我想以FactInternetSales表为入口,扩大它的数据量到数亿条.
经过分析,我觉得只要把理解主键是怎么生成的,以及orderdatekey,duedatekey,shipdatekey修改下,随机生成productkey与customerkey
(其实是随机从这两个维表中抽取key),基本上就可以装配好数据.
以下是我的代码,仅供参考.欢迎同学们提供更好的思路.
我现在是先取出salesordernumber最大的那个,然后基于这个进行递加,还有maxorderdate.
一天随机抽取300个产品和1000个客户进行匹配,这样就可以产生三十万条记录.
如果循环700次,因为怕DimDate里面的key不存在(可以自己扩容DimDate) ,可以保证DateKey是在DimDate里面还有.
即可创建大约二亿条数据.基本可以满足测试的需求了.
随机是使用order by newid()来实现的,然后通过row_number() 来生成行号再加上当前最大的那个salesordernumber来作为新的.
declare
@maxsonumber int,
@maxorderdate date,
@loopcount int
select
@maxsonumber = max(cast(replace(salesordernumber,left(salesordernumber,2),'') as int)),
@maxorderdate =
CAST( substring(cast(max(orderdatekey) as varchar),1,4)
+'-'+substring(cast(max(orderdatekey) as varchar),5,2)
+'-'+substring(cast(max(orderdatekey) as varchar),7,2)
as DATE)
from FactInternetSales
select @maxorderdate--
select @maxsonumber-- set @loopcount = 1 while @loopcount < 100
BEGIN
BEGIN TRAN BEGIN TRY
INSERT INTO [AdventureWorksDW2008R2].[dbo].[FactInternetSales]
([ProductKey]
,[OrderDateKey]
,[DueDateKey]
,[ShipDateKey]
,[CustomerKey]
,[PromotionKey]
,[CurrencyKey]
,[SalesTerritoryKey]
,[SalesOrderNumber]
,[SalesOrderLineNumber]
,[RevisionNumber]
,[OrderQuantity]
,[UnitPrice]
,[ExtendedAmount]
,[UnitPriceDiscountPct]
,[DiscountAmount]
,[ProductStandardCost]
,[TotalProductCost]
,[SalesAmount]
,[TaxAmt]
,[Freight]
,[CarrierTrackingNumber]
,[CustomerPONumber])
SELECT
[ProductKey]
,replace(cast(dateadd(dd,1,@maxorderdate)as varchar),'-','')
,replace(cast(dateadd(dd,1,@maxorderdate)as varchar),'-','')
,replace(cast(dateadd(dd,DaysToManufacture,@maxorderdate) as varchar),'-','')
,[CustomerKey]
,1
,100
,10
,'SO'+CAST(@maxsonumber+rowno AS VARCHAR)
,1
,1
,1
,DealerPrice
,DealerPrice
,0
,0
,StandardCost
,StandardCost
,DealerPrice
,0
,0
,NULL
,NULL
FROM
(
SELECT
ROW_NUMBER() over(order by newid()) as rowno,
*
FROM
(SELECT TOP 300 ProductKey,DealerPrice,StandardCost,DaysToManufacture FROM DimProduct
WHERE DealerPrice IS NOT NULL AND StandardCost is not null ORDER BY NEWID()) AS P
CROSS JOIN
(SELECT TOP 1000 CustomerKey FROM DimCustomer ORDER BY NEWID()) AS C
) AS X
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE()
IF @@TRANCOUNT >0
ROLLBACK TRAN;
END CATCH
IF @@TRANCOUNT >0
COMMIT TRAN; select
@maxsonumber = max(cast(replace(salesordernumber,left(salesordernumber,2),'') as int)),
@maxorderdate =
CAST( substring(cast(max(orderdatekey) as varchar),1,4)
+'-'+substring(cast(max(orderdatekey) as varchar),5,2)
+'-'+substring(cast(max(orderdatekey) as varchar),7,2)
as DATE)
from FactInternetSales print 'maxsonumber:' + cast(@maxsonumber as varchar)
print 'maxorderdate:' + cast(@maxorderdate as varchar) SET @loopcount += 1
END
MSBI--enlarge the DW database table volume的更多相关文章
- What is the difference between database table and database view?
The database table has a physical existence in the database. A view is a virtual table, that is one ...
- How do I see what character set a database / table / column is in MySQL?
Q: How do I see what the character set that a MySQL database, table and column are in? Is there some ...
- SAP技术 - How to create a CDS redirect view for a given database table
Scenario Suppose we have a database table A, and then we create a CDS redirect view B for it, then e ...
- 对PostgreSQL中tablespace 与 database, table的理解
开始: 当前的tablesapce信息 pgsql=# select * from pg_tablespace; spcname | spcowner | spclocation | spcacl | ...
- CMD Create Database & Table
Just do it: /* SQL 创建库 CREATE DATABASE jsp_demo DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ...
- HAWQ 官方文档创建filespace,tablespace,database,table
1.创建Filespace 创建Filespace必须是数据库超级用户( You must be a database superuser to create a filespace.)首先创建一个f ...
- hawq创建filespace,tablespace,database,table
使用HAWQ 在HAWQ的使用上跟Greenplum基本就一样一样的了.比如: 1. 创建表空间 #选创建filespace,生成配置文件 [gpadmin@master ~]$ hawq f ...
- MySQL删除数据库或表(DROP DATABASE/table语句)
DROP DATABASE [ IF EXISTS ] <数据库名> DROP table[ IF EXISTS ] <数据库表名> 语法说明如下: <数据库名>: ...
- mysqldump database table
一)在同一个数据库服务器上面进行数据表间的数据导入导出: 1. 如果表tb1和tb2的结构是完全一样的,则使用以下的命令就可以将表tb1中的数据导入到表tb2中: insert into db2.tb ...
随机推荐
- [PHP] PHP请求Socket接口测试
使用php读取socket接口的数据,通过php传递请求方法和请求参数,得到返回结果 PHP文件: <?php class Test{ const IP='127.0.0.1'; const p ...
- 一些经典===>>用SQL语句操作数据
用SQL语句操作数据 结构化查询语言(Structured Query Language)简称SQL(发音:/ˈes kjuː ˈel/ "S-Q-L"),是一种特殊目的的编程语言 ...
- Maven的安装使用以及 Maven+Spring hello world example
关于Maven Maven是一个用于项目构建的工具,通过它便捷的管理项目的生命周期.即项目的jar包依赖,开发,测试,发布打包. 做过.NET的人应该会联想到Nuget,是的Maven其实就是java ...
- webpack打包
(1) 首先生成一个package.json文件 进入项目文件的根目录执行npm init 在根目录中生成一个package.json文件 (2)全局安装webpack 执行npm install ...
- Android破解之北斗手机定位系统
我想破解GIS相关的安卓程序,于是找到了这个北斗手机定位系统,且不论它是否能定位,定位精度有多高,本文件只进行破解分析. 在模拟器中安装,输入手机号码,点击"卫星定位",它会一级一 ...
- Microsoft Dynamics CRM 前瑞开发
做CRM开发最大的感受就是其前瑞开发过程中,调试起来比较麻烦,需要做一些断点还要配制一些浏览器设置,对新手来说比较困难.还有就是对REST调试,经常为了调试一个正确的结果而花费大量的时间.现在推荐一个 ...
- java中判断字符串是否为数字的方法
一: //1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); ...
- 转:【前端福利】用grunt搭建自动化的web前端开发环境-完整教程
原文地址:http://blog.csdn.net/wangfupeng1988/article/details/46418203 jQuery在使用grunt,bootstrap在使用grunt,百 ...
- 参加2013中国大数据技术大会(BDTC2013)
2013年12月5日-6日参加了为期两天的2013中国大数据技术大会(Big Data Technology Conference, BDTC2013),本期会议主题是:“应用驱动的架构与技术 ”.大 ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q48-Q50)
Question 48You create a user control named MySearchBox.ascx.You plan to change the native search con ...