|
Python Connector for SQL Server Using the module - Python Connector for SQL Server |
|
To retrieve data from SQL Server:
import devart.sqlserver
connect() module method and obtain a connection object:
my_connection = devart.sqlserver.connect("Authentication=SQLServer;Server=your_server;Database=your_database;UserId=your_username;Password=your_password")
my_connection = devart.sqlserver.connect("Authentication=Windows;Server=your_server;Database=your_database")
cursor object using the cursor() connection method.
my_cursor = my_connection.cursor()
execute() cursor method.
my_cursor.execute("SELECT * FROM employees")
fetch*() cursor methods.
for row in my_cursor.fetchall():
print(row)