SQLServer 批量導入目錄文件
更新時間:2009年08月27日 01:02:59 作者:
可以用擴展存儲過程xp_dirtree獲取文件列表,用openrowset倒入數(shù)據(jù)到二進制字段。
openrowset的用法可以參考msdn
http://technet.microsoft.com/zh-cn/library/ms190312.aspx
如果文件很多,建議還是用程序倒入了
if (object_id ('t_bulkResult' ) is not null )
drop table t_bulkResult
create table t_bulkResult (name varchar (1000 ), data image )
go
declare @d varchar (1000 )
set @d = 'c:\test\'
create table #tb (fName varchar (1000 ), d int , f int )
insert into #tb exec xp_dirtree @d , 1 , 1
delete from #tb where f <> 1
declare @ sql nvarchar (max )
select @ sql = isnull (@ sql , '' )+ 'insert into t_bulkResult select ''' +@d + fname + ''',* from openrowset(bulk N''' +@d + fName + ''', SINGLE_BLOB) b
'
from #tb a
exec sp_executesql @ sql
drop table #tb
select * from t_bulkResult
http://technet.microsoft.com/zh-cn/library/ms190312.aspx
如果文件很多,建議還是用程序倒入了
復制代碼 代碼如下:
if (object_id ('t_bulkResult' ) is not null )
drop table t_bulkResult
create table t_bulkResult (name varchar (1000 ), data image )
go
declare @d varchar (1000 )
set @d = 'c:\test\'
create table #tb (fName varchar (1000 ), d int , f int )
insert into #tb exec xp_dirtree @d , 1 , 1
delete from #tb where f <> 1
declare @ sql nvarchar (max )
select @ sql = isnull (@ sql , '' )+ 'insert into t_bulkResult select ''' +@d + fname + ''',* from openrowset(bulk N''' +@d + fName + ''', SINGLE_BLOB) b
'
from #tb a
exec sp_executesql @ sql
drop table #tb
select * from t_bulkResult
相關文章
MSSQL監(jiān)控數(shù)據(jù)庫的DDL操作(創(chuàng)建,修改,刪除存儲過程,創(chuàng)建,修改,刪除表等)
下面就是一個解決上述問題的方案,我們通過創(chuàng)建一個表DatabaseLog和DDL觸發(fā)器來解決問題,首先在msdb數(shù)據(jù)庫里面新建一個表DatabaseLog,用來保存DDL觸發(fā)器獲取的信息2013-08-08mybatis調用sqlserver存儲過程返回結果集的方法
這篇文章主要介紹了mybatis調用sqlserver存儲過程返回結果集的方法,本文分兩種方法給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-05-05sql server刪除前1000行數(shù)據(jù)的方法實例
最近處理數(shù)據(jù)的時候遇到了個問題,需要利用sql刪除表格的前1000行數(shù)據(jù),嘗試過后這里給大家分享下過程,所以下面這篇文章主要給大家介紹了關于sql server刪除前1000行數(shù)據(jù)的相關資料,需要的朋友可以參考下2021-08-08SQLServer EVENTDATA()函數(shù)來獲取DDL 觸發(fā)器信息
SQL Server 2005/2008中可以使用EVENTDATA函數(shù)來獲取DDL觸發(fā)器的上下文,從而在ROLLBACK之前截獲DDL信息。EVENTDATA返回XML字段,下面的例子顯示如何截獲Drop Table的DDL信息。2009-07-07