Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyodbc
- # creating a new db to load Iris sample in
- new_db_name = "MLRemoteExec"
- connection_string = "Driver=SQL Server;Server=localhost\MSSQLSERVER2017;Database={0};Trusted_Connection=Yes;"
- # you can also swap Trusted_Connection for UID={your username};PWD={your password}
- cnxn = pyodbc.connect(connection_string.format("master"), autocommit=True)
- cnxn.cursor().execute("IF EXISTS(SELECT * FROM sys.databases WHERE [name] = '{0}') DROP DATABASE {0}".format(new_db_name))
- cnxn.cursor().execute("CREATE DATABASE " + new_db_name)
- cnxn.close()
- print("Database created")
Add Comment
Please, Sign In to add comment