Add csv file to Synapse Studio

Jake Watson 0 Reputation points
2024-04-10T15:26:21.5733333+00:00

I just want to add a csv file to my azure synapse workspace. Seems simple enough, but microsoft makes it not so.

I have the csv file loaded into a container, and it's accessible from my linked services, but the headers are not properly formatted. I'd like to add this as a table that I can query from in synapse and join other tables.

I've tried going through the data ingest copy tool, but it won't connect.

Screenshot 2024-04-10 at 11.24.11 AM.png

Screenshot 2024-04-10 at 11.24.38 AM.png

Screenshot 2024-04-10 at 11.24.02 AM.png

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Smaran Thoomu 24,110 Reputation points Microsoft External Staff Moderator
    2024-04-11T10:21:31.8566667+00:00

    Hi @Jake Watson

    Thanks for the question and using MS Q&A platform.

    To create a table from a CSV file in Synapse Analytics, you can use the following steps:

    • Upload the CSV file to an Azure Blob Storage container. You can do this using the Azure portal or Azure Storage Explorer.
    • Create an external data source in Synapse Analytics that points to the Azure Blob Storage container where the CSV file is located. You can do this using the following T-SQL command:
    CREATE EXTERNAL DATA SOURCE MyDataSource
    WITH (
        TYPE = BLOB_STORAGE,
        LOCATION = 'https://mystorageaccount.blob.core.windows.net/mycontainer',
        CREDENTIAL = MyCredential
    );
    

    In this example, MyDataSource is the name of the external data source, https://mystorageaccount.blob.core.windows.net/mycontainer is the URL of the Azure Blob Storage container where the CSV file is located, and MyCredential is the name of the credential that provides access to the container.

    Create an external file format in Synapse Analytics that describes the format of the CSV file. You can do this using the following T-SQL command:

    CREATE EXTERNAL FILE FORMAT MyFileFormat
    WITH (
        FORMAT_TYPE = DELIMITEDTEXT,
        FORMAT_OPTIONS (
            FIELD_TERMINATOR = ',',
            STRING_DELIMITER = '"',
            FIRST_ROW = 2
        )
    );
    

    In this example, MyFileFormat is the name of the external file format, and the FORMAT_OPTIONS specify the delimiter, string delimiter, and whether the first row contains headers.

    Create an external table in Synapse Analytics that references the CSV file. You can do this using the following T-SQL command:

    CREATE EXTERNAL TABLE MyTable
    (
        Column1 INT,
        Column2 VARCHAR(50),
        Column3 DATE
    )
    WITH (
        LOCATION = '/path/to/myfile.csv',
        DATA_SOURCE = MyDataSource,
        FILE_FORMAT = MyFileFormat,
        REJECT_TYPE = VALUE,
        REJECT_VALUE = 0
    );
    

    In this example, MyTable is the name of the external table, and the columns are defined based on the structure of the CSV file. The LOCATION specifies the path to the CSV file within the Azure Blob Storage container, and the DATA_SOURCE and FILE_FORMAT reference the external data source.

    I hope this helps! Let me know if you have any further questions.

    1 person found this answer helpful.

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.