HOW TO
Connecting to SQL Server and making SQL queries can be incorporated into Python to aid common GIS geoprocessing tasks.
The procedures below describe how to connect to a SQL Server database and make SQL queries from Python.
Note: Since ArcGIS Desktop by default installs the 32-bit version of Python, install the 32-bit version of pyodbc.
con = pyodbc.connect('DRIVER={SQL Server};SERVER=Prod1\SQL2008R2;DATABASE=SDE;UID=sa;PWD=sa')
con = pyodbc.connect('Trusted_Connection=yes', driver = '{SQL Server}',server = ‘Prod1\SQL2008R2 ‘, database = ‘SDE')
cur = con.cursor()
querystring = "select * into ParcelsA from ParcelsB"
cur.execute(querystring) con.commit()
Get help from ArcGIS experts
Download the Esri Support App