Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. import pymssql
  2. ip = '167.114.136.105'
  3. database_connection = pymssql.connect(host=ip, port=1433, user='fusezedc', password='.Towhitch01', database='fusezedc_koc-scripts')
  4. cursor = conn.cursor()
  5. cursor.execute("""
  6. IF OBJECT_ID('persons', 'U') IS NOT NULL
  7.    DROP TABLE persons
  8. CREATE TABLE persons (
  9.    id INT NOT NULL,
  10.    name VARCHAR(100),
  11.    salesrep VARCHAR(100),
  12.    PRIMARY KEY(id)
  13. )
  14. """)
  15. cursor.executemany(
  16.     "INSERT INTO persons VALUES (%d, %s, %s)",
  17.     [(1, 'John Smith', 'John Doe'),
  18.      (2, 'Jane Doe', 'Joe Dog'),
  19.      (3, 'Mike T.', 'Sarah H.')])
  20. # you must call commit() to persist your data if you don't set autocommit to True
  21. conn.commit()
  22.  
  23. cursor.execute('SELECT * FROM persons WHERE salesrep=%s', 'John Doe')
  24. row = cursor.fetchone()
  25. while row:
  26.     print("ID=%d, Name=%s" % (row[0], row[1]))
  27.     row = cursor.fetchone()
  28.  
  29. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement