我正在尝试在MS SQL 2008中构建一个表,该表加载了大约50,000行数据。现在我正在做类似的事情:
Create Table MyCustomData
(
ColumnKey Int Null,
Column1 NVarChar(100) Null,
Column2 NVarChar(100) Null
Primary Key Clustered
(
ColumnKey ASC
)
WITH (
PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON
)
)
CREATE INDEX IDX_COLUMN1 ON MyCustomData([COLUMN1])
CREATE INDEX IDX_COLUMN2 ON MyCustomData([COLUMN2])
DECLARE @MyCount Int
SET @MyCount = 0
WHILE @MyCount < 50000
BEGIN
INSERT INTO MyCustomData
(ColumnKey, Column1, Column2)
Select @MyCount + 1, 'Custom Data 1', 'Custom Data 2'
Set @MyCount = @MyCount + 1
END
我的问题是,这是疯狂的慢。我曾经想过,我可以创建一个Select语句来构建我的自定义数据,并将其用作Insert Into语句的数据源。
即。
之类的东西INSERT INTO MyCustomData
(ColumnKey, Column1, Column2)
From (Select Top 50000 Row_Count(), 'Custom Data 1', 'Custom Data 2')
我知道这不起作用,但我能展示的唯一一件事似乎就是我所追求的一个例子。任何建议都会受到很大关注。
答案 0 :(得分:1)
http://www.mysqlperformanceblog.com/2011/02/01/sample-datasets-for-benchmarking-and-testing/
一些用于测试的样本数据集。
另一种选择是使用您选择的语言在csv文件中创建数据,然后将其导入SQL Server,这将比您当前的方法快得多。
答案 1 :(得分:1)
好吧,如果我想要50000行具有常量数据和计数器,我会去
select row_number() over(order by t1.[number]), 'Custom data 1', 'Custom data 2'
from
master..spt_values as t1
cross join (select [number] from master..spt_values where [type] = 'P' and [number] between 1 and 50) as t2
where
[type] = 'P' and t1.[number] between 1 and 1000