Skip to content

Commit f07770e

Browse files
committed
changes from feedback
1 parent 1d8aff3 commit f07770e

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

docs-ref-services/sql.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Connect to Azure SQL database using the ODBC driver and pyodbc or m
44
author: lisawong19
55
ms.author: liwong
66
manager: routlaw
7-
ms.date: 01/05/2018
7+
ms.date: 01/09/2018
88
ms.topic: reference
99
ms.devlang: python
1010
ms.service: sql-database
@@ -14,47 +14,62 @@ ms.service: sql-database
1414

1515
## Overview
1616

17-
Work with data stored in [Azure SQL Database](/azure/sql-database/sql-database-technical-overview) from Python with the Microsoft ODBC driver and pyodbc. View our [quickstart](https://docs.microsoft.com/azure/sql-database/sql-database-connect-query-python) and getting started [sample](https://github.com/Azure-Samples/sql-database-python-manage).
17+
Work with data stored in [Azure SQL Database](/azure/sql-database/sql-database-technical-overview) from Python with the pyodbc [ODBC database driver](https://github.com/mkleehammer/pyodbc/wiki/Drivers-and-Driver-Managers). View our [quickstart](https://docs.microsoft.com/azure/sql-database/sql-database-connect-query-python) on connecting to an Azure SQL database and using Transact-SQL statements to query data and getting started [sample](https://github.com/mkleehammer/pyodbc/wiki/Getting-started) with pyodbc.
18+
19+
20+
## Connecting to ORMs
21+
22+
pyodbc works with other ORMs such as [SQLAlchemy](http://docs.sqlalchemy.org/en/latest/dialects/mssql.html?highlight=pyodbc#module-sqlalchemy.dialects.mssql.pyodbc) and [Django](https://github.com/lionheart/django-pyodbc/).
23+
1824

1925
## Install ODBC driver and pyodbc
2026

2127
```bash
2228
pip install pyodbc
2329
```
24-
More details about installing the python and database communication libraries can be found [here](https://docs.microsoft.com/azure/sql-database/sql-database-connect-query-python#install-the-python-and-database-communication-libraries).
30+
More [details](https://docs.microsoft.com/azure/sql-database/sql-database-connect-query-python#install-the-python-and-database-communication-libraries) about installing the python and database communication libraries.
2531

26-
### Connect and execute an SQL query
32+
## Connect and execute a SQL query
2733

28-
Connect to a SQL database and select all records in a table.
34+
### Connect to a SQL database
2935

3036
```python
31-
import pyodbc
37+
import pyodbc
3238

33-
SERVER = 'YOUR_SERVER_NAME.database.windows.net'
34-
DATABASE = 'YOUR_DATABASE_NAME'
35-
USERNAME = 'YOUR_DB_USERNAME'
36-
PASSWORD = 'YOUR_DB_PASSWORD'
39+
server = 'your_server.database.windows.net'
40+
database = 'your_database'
41+
username = 'your_username'
42+
password = 'your_password'
43+
driver= '{ODBC Driver 13 for SQL Server}'
3744

38-
DRIVER= '{ODBC Driver 13 for SQL Server}'
39-
cnxn = pyodbc.connect('DRIVER=' + DRIVER + ';PORT=1433;SERVER=' + SERVER +
40-
';PORT=1443;DATABASE=' + DATABASE + ';UID=' + USERNAME + ';PWD=' + PASSWORD)
45+
cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password)
4146
cursor = cnxn.cursor()
42-
selectsql = "SELECT * FROM SALES" # SALES is an example table name
43-
cursor.execute(selectsql)
4447
```
4548

46-
## Management API
49+
### Execute a SQL query
50+
51+
```python
52+
cursor.execute("SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName FROM [SalesLT].[ProductCategory] pc JOIN [SalesLT].[Product] p ON pc.productcategoryid = p.productcategoryid")
53+
row = cursor.fetchone()
54+
while row:
55+
print (str(row[0]) + " " + str(row[1]))
56+
row = cursor.fetchone()
57+
```
58+
59+
> [!div class="nextstepaction"]
60+
> [pyodbc sample]()
61+
62+
## [Management API](/python/api/overview/azure/sql/managementlibrary)
4763

4864
Create and manage Azure SQL Database resources in your subscription with the management API.
4965

5066
```bash
51-
pip install azure-mgmt-sql
5267
pip install azure-common
5368
pip install azure-mgmt-sql
5469
pip install azure-mgmt-resource
5570
```
5671

57-
### Example
72+
## Example
5873

5974
Create a SQL Database resource and restrict access to a range of IP addresses using a firewall rule.
6075

0 commit comments

Comments
 (0)