Linked Server Insert-Select Performance

后端 未结 6 625
时光取名叫无心
时光取名叫无心 2021-01-02 17:30

Assume that I have a table on my local which is Local_Table and I have another server and another db and table, which is Remote_Table (table struct

6条回答
  •  悲哀的现实
    2021-01-02 18:31

    I've found a workaround. Since I'm not a big fun of GUI tools like SSIS, I've reused a bcp script to load table into csv and vice versa. Yeah, it's an odd case to have the bulk operation support for files, but tables. Feel free to edit the following script to fit your needs:

    exec xp_cmdshell 'bcp "select * from YourLocalTable" queryout C:\CSVFolder\Load.csv -w -T -S .' 
    exec xp_cmdshell 'bcp YourAzureDBName.dbo.YourAzureTable in C:\CSVFolder\Load.csv -S yourdb.database.windows.net -U youruser@yourdb.database.windows.net -P yourpass -q -w' 
    

    Pros:

    • No need to define table structures every time.
    • I've tested and it worked way faster than inserting directly through the LinkedServer.
    • It's easier to manage than XML (which is limited to varchar(max) length anyway).
    • No need of an extra layout of abstraction (tools like SSIS).

    Cons:

    • Using the external tool bcp through the xp_cmdshell interface.
    • Table properties will be lost after ex/im-poring csv (i.e. datatype, nulls,length, separator within value, etc).

提交回复
热议问题