Create Python apps using SQL Server on Windows
In this section, you will get SQL Server 2017 on Windows. After that you will install the necessary dependencies to create Python apps with SQL Server.
Step 1.1 Install SQL Server
- If you don’t have SQL Server 2017 Developer (or above) installed, click here to download the SQL Server exe.
- Run it to start the SQL installer.
- Click Basic in Select an installation type.
- Click Accept after you have read the license terms.
- (Optional) if you need to, you can choose a custom installation location for SQL Server.
- Click Install to proceed with the installation.
You now have SQL Server installed and running locally on your Windows computer! Check out the next section to continue installing prerequisites.
Step 1.2 Install Python
Download and run the installer here
Next, add Python to your path
- Press start
- Search for “Advanced System Settings”
- Click on the “Environment Variables” button
- Add the location of the Python27 folder to the PATH variable in System Variables. The following is a typical value for the PATH variable C:\Python27
You have succesfully installed Python on your machine!
Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
SQLCMD is a command line tool that enables you to connect to SQL Server and run queries.
After installing SQLCMD, you can connect to SQL Server using the following command from a CMD session:
sqlcmd -S localhost -U sa -P your_password 1> # You're connected! Type your T-SQL statements here. Use the keyword 'GO' to execute each batch of statements.
This how to run a basic inline query. The results will be printed to STDOUT.
sqlcmd -S localhost -U sa -P yourpassword -Q "SELECT @@VERSION"
-------------------------------------------------------- Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) Apr 29 2016 23:23:58 Copyright (c) Microsoft Corporation Developer Edition (64-bit) 1 rows(s) returned Executed in 1 ns.
You have successfully installed SQL Server Command Line Utilities on your Windows machine!