从表到表的最快插入方法

我通常使用以下查询进行插入。 但这次,我将使用此查询进行1500万条记录。 这样很慢。 我该如何快速?

将仅传输Id(Guid),Code(nvarchar)和pool(guid)值。如您所见,默认设置为“休息”。

谢谢。

insert into collection
select Id,GETDATE(),'00000000-0000-0000-0000-000000000000',Code,pool,1 from collectiontemp
where pool='0929B522-AF2A-4B36-xxxx-xxxxxxxxxxxx'
bingjie000407 回答:从表到表的最快插入方法

此查询很好:

insert into collection
    select Id,GETDATE(),'00000000-0000-0000-0000-000000000000',Code,pool,1
    from collectiontemp
    where pool = '0929B522-AF2A-4B36-xxxx-xxxxxxxxxxxx';

除了在collectiontemp(pool)上建立索引之外,没有其他明显的方法可以加快它的运行速度。

但是,如果您正在用该pool的不同值调用这个查询1500万次,那将是昂贵的!要加载整个表,请删除where子句:

insert into collection
    select Id,1
    from collectiontemp;

如果您有少量值,请使用IN在一个查询中列出它们:

insert into collection
    select Id,1
    from collectiontemp
    where pool in ( . . . );
本文链接:https://www.f2er.com/3132988.html

大家都在问