在我的应用程序中,我将 TADOQuery 与 select (MSSQL) 一起使用并与 TClientDataSet 链接。我必须插入大约百万条记录和 ApplyUpdates。
那么我在 SQL Server Profiler 中看到了什么?我看到对于每个插入的行,我们有 3 个查询:插入脚本的 sp_prepare、带有一些值的 sp_execute 和 sp_unprepare。
我只想在插入之前为所有记录准备一次sql,然后再取消准备。我该怎么做?
之后添加:
在查询中,我有一个用于执行存储过程的脚本:
tmpQuery := DefineQuery(FConnection, [
'exec up_getOperatorDataSet ',
' @tablename = :tablename, ',
' @operator = :operator, ',
' @forappend = :forappend, ',
' @withlinksonly = :withlinksonly, ',
' @ids = :ids '
], [
Param(ftString, sTableName),
Param(ftInteger, FOperatorId),
Param(ftBoolean, opForAppendOnly in OpenParams),
Param(ftBoolean, opOnlyWithModelLinks in OpenParams),
Param(ftString, sIds)
], Result);
它使用一些参数从表sTableName中选择所有字段。
从分析器插入的示例:
第1步:
declare @p1 int
set @p1=486
exec sp_prepare @p1 output,N'@P1 int,@P2 int,@P3 datetime,@P4 int,@P5 int,@P6 int,@P7 int,@P8 int,@P9 varchar(128),@P10 bit,@P11 numeric(19,4),@P12 smallint,@P13 smallint,@P14 smallint,@P15 smallint',N'insert into parser_prices
(operator_id, request_id, date, nights, model_hotel_id, model_meal_id, model_room_id, model_htplace_id, spo, hotelstop, price, frout_econom, frout_business, frback_econom, frback_business)
values
(@P1, @P2, @P3, @P4, @P5, @P6, @P7, @P8, @P9, @P10, @P11, @P12, @P13, @P14, @P15)
',1
select @p1
第2步:
exec sp_execute 486,21,2000450,'2009-12-04 00:00:00',14,2118,22,-9555,18,'2009-10.MSK.Bali.13.10.09-27.03.10',0,15530.0000,3,3,3,3
第 3 步:
exec sp_unprepare 486
它适用于所有新行。