Import Proc definition from network file with BULK

心已入冬 提交于 2020-01-05 06:38:55

问题


I'm trying to create 1000+ Procs in MS SQL from supplied physical files as part of legacy migration located on Network . For now I plan to use sp with dynamic SQL to loop over all of them like in segment below, I had problem with BULK ROWTERMINATOR, so I just dummied it with bunch of ZZZZ, is there any other correct way to set it to NONE, so all string will be loaded into single row for run. I also use Nvarchar(Max) for my field.

DROP TABLE IF EXISTS #imp;
CREATE TABLE #imp (Col varchar(max))
BULK INSERT  #imp
FROM '//TFSNetwork/log/Install/sp_Test02.sql'
  WITH (ROWTERMINATOR = '\nzzzzzzzzzZZZ')      ---<< ?????
select top 1 @Sql = Col from #imp
 EXEC (@sql);

----------------------------------------------------sp_Test02.sql
CREATE PROCEDURE [dbo].[sp_Test]   
AS  
BEGIN  
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
    SET NOCOUNT ON;
    SELECT GETDATE() AS TS
END

-----------------------------------------------------------------

Load whole file into single row/column

回答1:


ROWTERMINATOR = '\n' is what used by default ,that's why you get it once omitted at all. Don't think we can or will want to change this behavior rather use your Z combo). Same thing can be done with another BULK , in this case no need any ROWTERM options.

declare @myFile varchar(max) 
select @myFile = BulkColumn
from openrowset(BULK '//Network/Path/Test02.sql', single_blob) x;
SELECT @myFile


来源:https://stackoverflow.com/questions/57630968/import-proc-definition-from-network-file-with-bulk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!