Integrating CSV data into Azure SQL Server can streamline your data management processes. This tutorial guides you through setting up Azure SQL, preparing your Python environment, and executing the import script.
1.Set Up Azure SQL Server and Database
- Log into your Azure portal.
- Navigate to SQL Servers and click Create.

- Fill in the required details: Server name, Admin login, Password, and select the appropriate region.


- After creating the server, go to SQL Databases and click Create

2.Prepare Your Environment
- Ensure Python is installed on your machine.
- Create a
requirements.txt
file with the following content:
pyodbc
fastapi
uvicorn[standard]
pydantic
csv
azure-identity
- Install the packages using:
pip install -r requirements.txt
- Download and install the ODBC Driver 18 for SQL Server from Microsoft’s official site.
- Using guide: https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver16

3.Clone and Run the Import Script
- Clone the repository containing the import script:
git clone https://github.com/vominhtri1991/Import_CSV_AzureSQL.git
- Navigate to the cloned directory and run the script. The tool will prompt you to input:
- Azure SQL Server name
- Azure SQL Database name
- Azure SQL username
- Azure SQL password
- Table using for importing data
- Path of CSV file include data reading
- Upon execution, the script will:
- Establish a connection to the Azure SQL Database.
- Read and parse the CSV file.
- Create a new table in the database if it doesn’t exist.
- Insert the CSV data into the table

- After script running complete check new table already create on Azure SQL Server Database with new data

4. Understanding the Script Functions:
- Function prepare_connection_string for prepare SQL string connection

- Function Prepare_data prepare CSV Data will be imported to Azure SQL Database:
- Load column (first row of csv file) to global variable colume_list (type list)
- Load data form csv file to global variable data_import

- Function Create_Table(table_name) create new table in Azure SQL Database

- Function Import_To_Sql(table_name) will import data read from variable data_import and execute SQL insert to Azure SQL Database

✅By following this guide, you can efficiently import CSV data into Azure SQL Server using Python, facilitating seamless data integration for your applications.
Move your data, not your stress — automate it with Python.