SQL Server Python tutorials
This article provides a list of tutorials and samples that demonstrate the use of Python with SQL Server 2017. Through these samples and demos, you will learn:
- How to run Python from T-SQL
- What are remote and local compute contexts, and how you can execute Python code using the SQL Server computer
- How to wrap Python code in a stored procedure
- Optimizing Python code for a SQL production environment
- Real-world scenarios for embedding machine learning in applications
For information about requirements and setup, see Prerequisites.
Learn the basics of how to call Python in T-SQL, using the extensibility mechanism pioneered in SQL Server 2016.
You'll create a model using rxLinMod, from the new revoscalepy library. You'll launch the code from a remote Python terminal but the modeling will take place in the SQL Server compute context.
NEW! Build a complete Python solution using T-SQL stored procedures. All Python code is included.
Learn how to deploy a Python model using the latest version of Microsoft Machine Learning Server.
These samples and demos provided by the SQL Server development team highlight ways that you can use embedded analytics in real-world applications.
Learn how a ski rental business might use machine learning to predict future rentals, which helps the business plan and staff to meet future demand.
Now includes native scoring from Python models!
Learn how to use the Kmeans algorithm to perform unsupervised clustering of customers.
To use these tutorials, you must have installed SQL Server 2017 Machine Learning Services (In-Database). SQL Server 2017 supports either R or Python. However, you must install the extensibility framework that supports machine learning, and select Python as the language to install. You can install both R and Python on the same computer.
Support for Python is a new feature in SQL Server 2017, and requires CTP 2.0 or later. Although the feature is in pre-release and not supported for production environments, we invite you to try it out and send feedback.
SQL Server 2017
After running SQL Server setup, don't forget these important steps:
- Enable the external script execution feature by running
sp_configure 'external scripts enabled', 1.
- Restart the server.
- Ensure that the service that calls the external runtime has necessary permissions.
- Ensure that your SQL login or Windows user account has necessary permissions to connect to the server, to read data, and to create any database objects required by the sample.
If you run into trouble, see this article for some common issues: Troubleshooting Machine Learning Services