Guest User

Untitled

a guest
Jul 11th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import pyodbc
  2.  
  3. # creating a new db to load Iris sample in
  4. new_db_name = "MLRemoteExec"
  5. connection_string = "Driver=SQL Server;Server=localhost\MSSQLSERVER2017;Database={0};Trusted_Connection=Yes;"
  6. # you can also swap Trusted_Connection for UID={your username};PWD={your password}
  7. cnxn = pyodbc.connect(connection_string.format("master"), autocommit=True)
  8. cnxn.cursor().execute("IF EXISTS(SELECT * FROM sys.databases WHERE [name] = '{0}') DROP DATABASE {0}".format(new_db_name))
  9. cnxn.cursor().execute("CREATE DATABASE " + new_db_name)
  10. cnxn.close()
  11.  
  12. print("Database created")
Add Comment
Please, Sign In to add comment