我想将文件从文件所在的本地计算机保存到远程数据库中。我想使用BCP命令来实现。如何做到这一点?
我的查询类似于以下内容:
INSERT INTO ExcelFileUploadedData(
Project,
SubProject,
LogicalName,FileName,
FileData)
SELECT
'Sample',
'Sample',
'BP',
'1.xls',
*
FROM OPENROWSET(BULK N'D:\File\File1.xls.zip', SINGLE_BLOB) rs
你可以试试这个
SET @TableQuery='CREATE TABLE [temp1](
[Id] [int] IDENTITY(1,1) NOT NULL,
Project [NVARCHAR(50)],
SubProject [NVARCHAR(50)],
LogicalName [NVARCHAR(50)],
FileName [NVARCHAR(50)],
FileData [NVARCHAR(50)],
CONSTRAINT [PK_temp1] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
'
EXEC(@TableQuery)
DECLARE @params NVARCHAR(max)
SET @params = N'@uploadData SINGLE_BLOB readonly'
SET @BulkInsertQuery =N'INSERT INTO [temp1] ( Project, SubProject,LogicalName,FileName,FileData)
select * from @uploadData';
print @BulkInsertQuery
EXEC sp_executesql @BulkInsertQuery, @params, @uploadData
// Enter Records from temp table into real table
INSERT INTO ExcelFileUploadedData(
Project,
SubProject,
LogicalName,FileName,
FileData)
SELECT
'Sample',
'Sample',
'BP',
'1.xls',
*
FROM [temp1]
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。