Background history
The SQL Server tools team at Microsoft introduced Notebooks to Azure Data Studio (ADS) around March 2019. Since then, data professionals from the SQL Server community have been posting and sharing knowledge on how to make the most of this awesome new feature. In this article, we will explore how to integrate Azure Data Studio notebooks with Python to create SQL Server containers.
Prerequisites
- Azure Data Studio installed (1.5.2 version or higher)
- Python v3 installed, along with its package manager (pip)
- Docker engine installed, configured and started on your laptop/computer
Introduction
Azure Data Studio notebooks provide a versatile platform for data professionals to work with SQL Server. By combining the power of Python and SQL, we can create SQL Server containers with ease. In this article, we will walk through the process of creating SQL Server containers using Python and Azure Data Studio notebooks.
Checking SQL Server images
Before we create a SQL Server container, let’s first check the available SQL Server images. We can do this using Python and the Docker SDK. The following code examples demonstrate how to check the available SQL Server images for Ubuntu-based and RHEL-based systems.
Creating a SQL container
Once we have identified the SQL Server image we want to use, we can proceed to create a SQL container. Using the Docker SDK for Python, we can easily create and manage containers through the API. The following code example demonstrates how to create a SQL container using Python.
Connecting to our SQL container
After creating the SQL container, we can connect to it using Azure Data Studio. By switching the notebook kernel to “SQL”, we can choose from an existing or create a new connection to SQL Server. Once connected, we can execute T-SQL code blocks to interact with the SQL instance.
Cleaning up the environment
Once we are done with the SQL container, it is important to clean up the environment to avoid wasting resources. The following code example demonstrates how to stop and remove the SQL container using the Docker SDK for Python.
Conclusion
Azure Data Studio notebooks provide a powerful platform for working with SQL Server. By integrating Python and SQL, we can easily create and manage SQL Server containers. This opens up a world of possibilities for DBAs and developers. Whether it’s creating customized dashboards, running diagnostic queries, or experimenting with new features, Azure Data Studio notebooks with Python offer a flexible and efficient solution.
What’s next?
Now that you have learned how to integrate Azure Data Studio notebooks with Python to create SQL Server containers, the possibilities are endless. You can create your own notebooks with pre-defined queries for diagnostic purposes or explore other ways to leverage this powerful combination. The GitHub repository mentioned in this article provides more examples to help you get started.
Thank you for reading!