Creating sql database table from csv schema file using Azure data factory

Anil 20 Reputation points
2024-12-11T00:58:02.5066667+00:00

Hi,

i have requirement, we will get schema files in csv(see below highlighted), there were around 100s of files.

here is sample schema csv file

TableName,columnae,LENGTH,vartype

Customer,custnumber,8,NUM

Customer,custname,100,char

Customer,custtype,12,char

Customer,custordernumber,20,NUM

using Azure data factory, i have to create Customer table with columns(custnumber,custname,custtype,custordernumber) with data types in the sql server table . i can't hard code the mapping since i have hundreds of file.

File doesn't have any data, it has only schema.

Can someone help me how to import this to sqlserver?

Thank you,

Anil

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,113 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Pinaki Ghatak 5,565 Reputation points Microsoft Employee
    2024-12-11T09:58:10.5433333+00:00

    Hello @Anil

    To create a SQL Server table from a CSV schema file using Azure Data Factory, you can follow these 8 steps:

    1. Create a pipeline in Azure Data Factory.
    2. Add a Copy Data activity to the pipeline.
    3. In the Source tab of the Copy Data activity, select the CSV schema file as the source dataset.
    4. In the Sink tab of the Copy Data activity, select the SQL Server table as the sink dataset.
    5. In the Mapping tab of the Copy Data activity, select the "Import schema" option.
    6. Click on the "Import schema" button and select the CSV schema file.
    7. Map the columns from the CSV schema file to the columns in the SQL Server table.
    8. Save and run the pipeline. This will create the SQL Server table with the columns and data types specified in the CSV schema file. Note that you will need to create the SQL Server table beforehand and make sure that the column names and data types match the ones specified in the CSV schema file.

    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.


  2. AnnuKumari-MSFT 33,986 Reputation points Microsoft Employee
    2024-12-17T06:28:52.23+00:00

    Hi @Anil ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your query here.

    It seems you want to create tables in SQL using the schema present in CSV metadata file for multiple tables where you can't hardcode the schema.

    ADF might not directly help here, you might need to write a python script to achieve this scenario and use Azure functions to run the code using ADF.

    Here is the sample code you could try to use and generate tables based on the schemas for each of the tables:

    createsqltablesusingschemafiles.txt

    Hope it helps. Kindly accept the answer by clicking on Accept answer button. Thankyou


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.