加快插入

时间:2013-10-31 21:06:08

标签: sql sql-server

我想加快这个插入。如果我注释掉插入行,那么查询需要几秒钟,但是如果我添加插入时,它似乎只处理大约每分钟100行。 我如何加快速度?

DECLARE @XML AS XML, @hDoc AS INT
SELECT @XML = XMLData FROM InventoryStockXML WHERE id =1  --1st row
EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML

;With xmlnamespaces (default 'http://www.epicor.com/Mfg/100')
INSERT INTO dbo.xmltest (PartNum,WarehouseCode,OnhandQty,Date_Value,Plant)
Select
    N.value('PartNum[1]', 'varchar(50)') PartNum,
    N.value('WarehouseCode[1]', 'varchar(10)') WarehouseCode,
    N.value('OnhandQty[1]', 'decimal(22,8)') OnhandQty,
    Convert(date,CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()),101)) AS Date_Value,
    @xml.value('(/ReportDataSet/Plant/Plant)[1]', 'varchar(20)') Plant
from 
    @xml.nodes('/ReportDataSet/StkPart') as T(n)

EXEC sp_xml_removedocument @hDoc --takes it out of memory
GO

以下是我正在使用的测试文件: http://wikisend.com/download/637998/Test.XML

以下是加载文件的代码:

DECLARE @SQL1 NVARCHAR (MAX),@xmlFileName1 VARCHAR(300)
select  @xmlFileName1 = 'C:\XMLInventoryFiles\Stock\Test.XML'
set @sql1 ='
INSERT INTO InventoryStockXML(XMLData, LoadedDateTime)
SELECT CONVERT(XML, BulkColumn) AS XMLData, GETDATE() XMLDate
FROM OPENROWSET(BULK ''' + @xmlFileName1 + ''', SINGLE_BLOB) AS x'
execute (@sql1)

0 个答案:

没有答案