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 ...
随机推荐
- ASP.NET MVC4 数据库连接(EF6.0)
我的博客原文地址:http://www.star110.com/Note/ReadArticle/60641215331146140041.html 环境:.NET MVC4 + EF6.0 连接数据 ...
- 浅谈ImageList
ImageList组件用了很久,但是一直不太清楚它的实现原理,今天专门特意花了时间倒腾了下,终于弄明白了!于是在这里和大家分享下! 在设计页面中打卡工具箱-组件 找到ImageList组件,将它直接拖 ...
- sql server 2008出现评估期已过的问题
我的sql server2008用来半年吧,那天的昨天还能用,到了180天后,就不能用了,具体问题如下: 出了这个问题后,就打不开sql server了 解决方法: 1.打开安装中心,升级sql se ...
- php学习笔记:对文件的增删查改等操作
文件的创建: 采用touch()函数,当文件不存在会被创建 例如: <?php header("Content-type: text/html; charset=utf-8" ...
- python模块基础之json,requeste,xml,configparser,logging,subprocess,shutil。
1.json模块 json 用于[字符串]和 [python基本数据类型] 间进行转换(可用于不同语言之前转换),json.loads,将字符串转成python的基本数据类型,json.dum ...
- GridView1_RowDataBound解决限制字段显示长度用"..."显示ToolTip
ToolTip: // // 摘要: // 获取或设置当鼠标指针悬停在 Web 服务器控件上时显示的文本. // // 返回结果: // 当鼠标指针悬停在 Web 服务器控件上时显示的文本.默认值为 ...
- 利用在线工具根据JSon数据自动生成对应的Java实体类
如果你希望根据JSon数据自动生成对应的Java实体类,并且希望能进行变量的重命名,那么“JSON To Java”一定适合你.(下面的地址需要FQ) https://jsontojava.appsp ...
- View的生命周期
当一个进入一个新viewController的时候,viewController的view的生命周期一般是这样的: 1.先判断内存是否有这个View a.没有的话:生命周期为loadView-> ...
- iOS使用Workspace来管理多项目
开发中会有一些常用的类或方法,或者是某个特定功能的,比如一个自定义的弹框.一个更容易使用的网络请求库,可以把它们放到一个单独的工程里,通过静态库(library.FrameWork)的方式应用到任何其 ...
- Java 实现多线程的三种方式
import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; public class Main { pu ...