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 ...
随机推荐
- iOS常用的几种数据存储方式
之前由于刚入行不久,对数据持久化不是很了解,尤其是用数据库存储大量数据的操作.经过摸索就在此总结一下,方便以后查阅 下面就简单介绍一下: 1.NSUserDefaults 感觉最常用的小量数据,属性, ...
- csharp: Procedure with DAO(Data Access Object) and DAL(Data Access Layer)
sql script code: CREATE TABLE DuCardType ( CardTypeId INT IDENTITY(1,1) PRIMARY KEY, CardTypeName NV ...
- [PHP] 实现路由映射到指定控制器
自定义路由的功能,指定到pathinfo的url上,再次升级之前的脚本 SimpleLoader.php <?php class SimpleLoader{ public static func ...
- 数组json格式的字符串 转 list<Bean>
1. 字符串形式: [ { "userid": "admin", "name": "admin", "pas ...
- Spring RMI Example
一: 提供服务的远程一端 1-1. applicationContext.xml <?xml version="1.0" encoding="UTF-8" ...
- Angularjs,WebAPI 搭建一个简易权限管理系统 —— Angularjs 前端主体结构(五)
目录 前言 Angularjs名词与概念 Angularjs 基本功能演示 系统业务与实现 WebAPI项目主体结构 Angularjs 前端主体结构 6 Angularjs 前端主体结构 6.1 A ...
- SQL数据库基础(三)
认识数据库备份和事务日志备份 数据库备份与日志备份是数据库维护的日常工作,备份的目的是在于当数据库出现故障或者遭到破坏时可以根据备份的数据库及事务日志文件还原到最近的时间点将损失降到最低点. 数据库备 ...
- 通过GPS数据反向地理信息编码, 得到当前位置信息
检查可用性 这属于基础知识, 不赘述, 总的来说,你的设备的支持要打开, 添加CoreLocation的framework, 引用头文件, 添加委托,然后, 好的实践是在使用前编程检查相关可用性: - ...
- AngularJS(一)
<!doctype html> <html ng-app=""> <!-- ng-app指令标记了AngularJS脚本的作用域 --> & ...
- SharePoint 2013 设置自定义布局页
在SharePoint中,我们经常需要自定义登陆页面.错误页面.拒绝访问等:不知道大家如何操作,以前自己经常在原来页面改或者跳转,其实SharePoint为我们提供了PowerShell命令,来修改这 ...