mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
files hosted elsewhere
These files have been relocated elsewhere
This commit is contained in:
-29
@@ -1,29 +0,0 @@
|
||||
import pyodbc
|
||||
import datetime
|
||||
server = 'your_server.database.windows.net'
|
||||
database = 'your_database'
|
||||
username = 'your_user'
|
||||
|
||||
|
||||
from azure.identity import DefaultAzureCredential
|
||||
from azure.keyvault.secrets import SecretClient
|
||||
|
||||
credential = DefaultAzureCredential()
|
||||
|
||||
secret_client = SecretClient(vault_url="https://<your_key_vault_name>.vault.azure.net", credential=credential)
|
||||
|
||||
# NOTE: please replace the ("<your-secret-name>") with the name of the secret in your vault
|
||||
secret = secret_client.get_secret("AppSecret")
|
||||
|
||||
password = secret.value
|
||||
|
||||
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
|
||||
cursor = cnxn.cursor()
|
||||
tsql = "SELECT SUM(Price) as sum FROM Table_with_3M_rows"
|
||||
a = datetime.datetime.now()
|
||||
with cursor.execute(tsql):
|
||||
b = datetime.datetime.now()
|
||||
c = b - a
|
||||
for row in cursor:
|
||||
print ('Sum:', str(row[0]))
|
||||
print ('QueryTime:', c.microseconds, 'ms')
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
import pyodbc
|
||||
server = 'your_server.database.windows.net'
|
||||
database = 'your_database'
|
||||
username = 'your_user'
|
||||
password = 'your_password'
|
||||
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
|
||||
cursor = cnxn.cursor()
|
||||
|
||||
print ('Inserting a new row into table')
|
||||
#Insert Query
|
||||
tsql = "INSERT INTO Employees (Name, Location) VALUES (?,?);"
|
||||
with cursor.execute(tsql,'Jake','United States'):
|
||||
print ('Successfully Inserted!')
|
||||
|
||||
|
||||
#Update Query
|
||||
print ('Updating Location for Nikita')
|
||||
tsql = "UPDATE Employees SET Location = ? WHERE Name = ?"
|
||||
with cursor.execute(tsql,'Sweden','Nikita'):
|
||||
print ('Successfully Updated!')
|
||||
|
||||
|
||||
#Delete Query
|
||||
print ('Deleting user Jared')
|
||||
tsql = "DELETE FROM Employees WHERE Name = ?"
|
||||
with cursor.execute(tsql,'Jared'):
|
||||
print ('Successfully Deleted!')
|
||||
|
||||
|
||||
#Select Query
|
||||
print ('Reading data from table')
|
||||
tsql = "SELECT Name, Location FROM Employees;"
|
||||
with cursor.execute(tsql):
|
||||
row = cursor.fetchone()
|
||||
while row:
|
||||
print (str(row[0]) + " " + str(row[1]))
|
||||
row = cursor.fetchone()
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
import pyodbc
|
||||
server = 'your_server.database.windows.net'
|
||||
database = 'your_database'
|
||||
username = 'your_user'
|
||||
|
||||
from azure.identity import DefaultAzureCredential
|
||||
from azure.keyvault.secrets import SecretClient
|
||||
|
||||
credential = DefaultAzureCredential()
|
||||
|
||||
secret_client = SecretClient(vault_url="https://<your_keyvault_name>.vault.azure.net", credential=credential)
|
||||
|
||||
# NOTE: please replace the ("<your-secret-name>") with the name of the secret in your vault
|
||||
secret = secret_client.get_secret("AppSecret")
|
||||
|
||||
password = secret.value
|
||||
|
||||
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
|
||||
cursor = cnxn.cursor()
|
||||
|
||||
|
||||
print ('Inserting a new row into table')
|
||||
#Insert Query
|
||||
tsql = "INSERT INTO Employees (Name, Location) VALUES (?,?);"
|
||||
with cursor.execute(tsql,'Jake','United States'):
|
||||
print ('Successfully Inserted!')
|
||||
|
||||
|
||||
#Update Query
|
||||
print ('Updating Location for Nikita')
|
||||
tsql = "UPDATE Employees SET Location = ? WHERE Name = ?"
|
||||
with cursor.execute(tsql,'Sweden','Nikita'):
|
||||
print ('Successfully Updated!')
|
||||
|
||||
|
||||
#Delete Query
|
||||
print ('Deleting user Jared')
|
||||
tsql = "DELETE FROM Employees WHERE Name = ?"
|
||||
with cursor.execute(tsql,'Jared'):
|
||||
print ('Successfully Deleted!')
|
||||
|
||||
|
||||
#Select Query
|
||||
print ('Reading data from table')
|
||||
tsql = "SELECT Name, Location FROM Employees;"
|
||||
with cursor.execute(tsql):
|
||||
row = cursor.fetchone()
|
||||
while row:
|
||||
print (str(row[0]) + " " + str(row[1]))
|
||||
row = cursor.fetchone()
|
||||
@@ -1,11 +0,0 @@
|
||||
## Sample details
|
||||
|
||||
Please visit the [Python tutorials](https://www.microsoft.com/en-us/sql-server/developer-get-started) and select RHEL, Ubuntu, SLES, or macOs to run through the sample in full with more detail.
|
||||
|
||||
<a name=disclaimers></a>
|
||||
|
||||
The scripts and this guide are provided as samples. They are not part of any Azure service and are not covered by any SLA or other Azure-related agreements. They are provided as-is with no warranties express or implied. Microsoft takes no responsibility for the use of the scripts or the accuracy of this document. Familiarize yourself with the scripts before using them.
|
||||
## Related Links
|
||||
|
||||
For more information, see these articles:
|
||||
* To see more getting started tutorials, visit our [tutorials page](https://www.microsoft.com/en-us/sql-server/developer-get-started/)
|
||||
Reference in New Issue
Block a user