简体   繁体   English

将所有 CSV 从本地驱动器上的路径加载到 AzureSQL DB w/Auto Create Tables

[英]Load all CSVs from path on local drive into AzureSQL DB w/Auto Create Tables

I frequently need to validate CSVs submitted from clients to make sure that the headers and values in the file meet our specifications.我经常需要验证客户提交的 CSV,以确保文件中的标头和值符合我们的规范。 Typically I do this by using the Import/Export Wizard and have the wizard create the table based on the CSV (file name becomes table name, and the headers become the column names).通常我通过使用导入/导出向导来执行此操作,并让向导根据 CSV 创建表(文件名成为表名,标题成为列名)。 Then we run a set of stored procedures that checks the information_schema for said table(s) and matches that up with our specs, etc.然后我们运行一组存储过程来检查所述表的 information_schema 并将其与我们的规范相匹配等。

Most of the time, this involves loading multiple files at a time for a client, which becomes very time consuming and laborious very quickly when using the import/export wizard.大多数时候,这涉及为客户端一次加载多个文件,这在使用导入/导出向导时变得非常耗时和费力。 I tried using an xp_cmshell sql script to load everything from a path at once to have the same result, but xp_cmshell is not supported by AzureSQL DB.我尝试使用 xp_cmshell sql 脚本一次从路径加载所有内容以获得相同的结果,但 AzureSQL DB 不支持 xp_cmshell。

https://learn.microsoft.com/en-us/azure/azure-sql/load-from-csv-with-bcp https://learn.microsoft.com/en-us/azure/azure-sql/load-from-csv-with-bcp

The above says that one can load using bcp, but it also requires the table to exist before the import... I need the table structure to mimic the CSV. Any ideas here?上面说可以使用 bcp 加载,但它也需要表在导入之前存在...我需要表结构来模仿 CSV。这里有什么想法吗?

Thanks谢谢

If you want to load the data into your target SQL db, then you can use Azure Data Factory[ ADF ] to upload your CSV files to Azure Blob Storage, and then use Copy Data Activity to load that data in CSV files into Azure SQL db tables - without creating those tables upfront . If you want to load the data into your target SQL db, then you can use Azure Data Factory[ ADF ] to upload your CSV files to Azure Blob Storage, and then use Copy Data Activity to load that data in CSV files into Azure SQL db表 -无需预先创建这些表。

ADF supports 'auto create' of sink tables. ADF 支持“自动创建”汇表。 See this , and this看到这个,还有这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM