大佬教程收集整理的这篇文章主要介绍了如何将大量 Varbinary(max) 行插入表中,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用本地 sql Server。我的桌子上有 25 万张照片 (DropPhotos
)。照片存储在名为 Varbinary(maX)
的 Content
列中。我想将所有这些行以及一些其他列移动到同一数据库 (BasePhotos
) 中的另一个表中。我写的sql语句是这样的:
INSERT INTO dbo.basePhotos (PhotoID,name,Content,AddedDate,CreationdatetiR_254_11845@e,PhotoTypE)
SELECT PhotoID,PhotoType
FROM dbo.DropPhotos
当我开始执行时,一切正常。几分钟(5 - 15 分钟)后,我的屏幕开始随机打开和关闭,然后关闭,几分钟后我的电脑重新启动。我怀疑移动如此多的二进制数据会耗尽所有 RAM 并导致关机。我在网上搜索了解决方案,发现存在某种批量插入。也许它可以帮助我?但据我所知,它用于从文件中插入行,而不是从另一个表中插入行。
所以我的问题很简单:如何将大量重行插入表中。
PhotoID 是唯一标识符@H_616_22@
更新:请注意,OP 要求在问题中移动记录,后来更改为在评论中复制记录。
上面讨论的批处理方法可以这样实现:
set nocount on
DECLARE @IdTable TABLE (id uniquEIDentifier)
insert into @IdTable(id)
SELEct top 100
dropPhotos.PhotoId
from
dbo.DropPhotos dropPhotos
left join dbo.basePhotos basePhotos on dropPhotos.PhotoId = basePhotos.PhotoId
where
basePhotos.PhotoId is null
while exists(SELEct top 1 1 from @IdTablE)
begin
INSERT INTO dbo.basePhotos (PhotoId,Name,Content,AddedDate,CreationdatetiR_254_11845@e,PhotoTypE)
SELECT PhotoId,PhotoType
FROM dbo.DropPhotos
WHERE PhotoId IN (SELEct id from @IdTablE)
delete from @IdTable
insert into @IdTable(id)
SELEct top 100
dropPhotos.PhotoId
from
dbo.DropPhotos dropPhotos
left join dbo.basePhotos basePhotos on dropPhotos.PhotoId = basePhotos.PhotoId
where
basePhotos.PhotoId is null
end
以上是大佬教程为你收集整理的如何将大量 Varbinary(max) 行插入表中全部内容,希望文章能够帮你解决如何将大量 Varbinary(max) 行插入表中所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。