This tutorial series shows you how to work with the SQL Server from Python using the pymssql package.
Python Drivers for SQL Server
To connect to the SQL Server from Python, you need a driver. There are some Python SQL Server drivers available.
Here are the drivers recommended by Microsoft:
- pyodbc – provides an interface for connecting to SQL Server databases via ODBC interface, allowing you to execute SQL queries seamlessly.
- pymssql – is a Python library designed for connecting to SQL Server databases and managing data efficiently.
We’ll use the pymssql
package to connect to the SQL Server from Python.
The pymssql Package Features
The following highlights some features of the pymssql
package:
- Python 3: Utilize the advantage of the latest features and improvements in Python 3.
- Unicode: Enable handling international characters.
- Works across popular operating systems (OS): Support the most popular OSes including Windows, macOS, or Linux.
- Written in Cython for performance: Benefit from faster execution and optimized performance.
- Supports stored procedures: Call SQL Server’s stored procedures with return values or output parameters.
- Supports bulk copy: Quickly and efficiently transfer large amounts of data to SQL Server.
- Can be used to connect to SQL Server on Azure: Seamlessly integrate with Microsoft’s cloud platform for scalable and reliable database solutions.
Section 1. Getting Started
- Connecting to the SQL Server – show you how to create a Python program that connects to the SQL Server.
Section 2. Inserting Data
- Insert data into a table – show you how to insert data into a table in SQL Server from Python
- Import a CSV file into a table – learn how to develop a Python program that reads data from a CSV file and imports it into a table in the SQL Server.
- Bulk Copy – discover how to quickly load data into an SQL Server table using the bulk copy function.
Section 3. Updating Data
- Update data from a table – Learn how to update data from a table using Python.
Section 4. Querying Data
- Select data from a table – Guide you on how to select one or more rows from a table in Python
- Pagination – Show you how to break up a large result set into smaller chunks (pages) using FETCH and OFFSET clauses.
Section 5. Deleting Data
- Delete data from a table – Show you how to delete data from a table in SQL Server from a Python application.
Section 6. Handling Transactions
- Perform a transaction – learn how to perform an SQL Server transaction from Python.
Section 7. Calling Stored Procedures
- Call a stored procedure – Learn to call a stored procedure in SQL Server from Python.
- Call a stored procedure with OUTPUT parameters – Show you how to call stored procedures with OUTPUT parameters from Python.
Was this tutorial helpful?