Migrating to Azure SQL (BCP)

烂漫一生 提交于 2019-12-08 13:33:01

问题


I am attempting to migrate a database from my local SQL server (SQL 2008 R2) to an Azure SQL installation.

Using a migration tool I found on the web, it has highlighted some issues where features are unavailable in Azure, the main one being BULK INSERT.

I have since replaced this feature with a call to xp_cmdshell to use BCP.

I am now getting an error that xp_cmdshell is unavailable in azure!

DECLARE @BCPString VARCHAR(255) = 'BCP ' + @DatabaseName + '.dbo.TEMP IN ' + @Path + ' -c -t "," -r "0x0a" -S ' + @ServerName + ' -T'

EXEC xp_cmdshell @BCPString, no_output

"xp_cmdshell is not supported in current version of Azure SQL Database"

Does anyone know of a workaround or another method to bulk import data which is usable in both SQL 2008 R2 and Azure SQL?

The import I need to perform is simple, it creates a table, imports, then the procedure deals with the rest with the table being dropped afterwards.


回答1:


you can use Bulk insert in Azure.First you have to create an external data source to a blob like below

CREATE EXTERNAL DATA SOURCE MyAzureInvoicesContainer
    WITH  (
        TYPE = BLOB_STORAGE,
        LOCATION = 'https://newinvoices.blob.core.windows.net/week3', 
        CREDENTIAL = UploadInvoices  
    );

Now you can use BULKINSERT like below

BULK INSERT tablename
FROM 'product.csv'
WITH (  DATA_SOURCE = 'MyAzureBlobStorage',
        FORMAT='CSV', CODEPAGE = 65001, --UTF-8 encoding
        FIRSTROW=2,
        TABLOCK); 

Azure (in coming months) supports a SQLAZURE managed instance(currently in preview now),this is same like OnPremises SQLServer with SQLAGent,CLR and stuff

Microsoft/sql-server-samples



来源:https://stackoverflow.com/questions/44116289/migrating-to-azure-sql-bcp

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