Skip to content

Instantly share code, notes, and snippets.

@h3xagn
Last active Aug 21, 2022
Embed
What would you like to do?
Extract data from SQL Server: https://h3xagn.com
# get list of history DBs
# note: check permission of the user to access 'master' database
query = "set nocount on; print 'Database';select name from sys.Databases where name like 'History%'"
sqlcmd = f'sqlcmd -S {server} -d ProcessDataDB -U {username} -P {password} -Q "{query}" -s "," -h -1 -W -o "./data/{site}_dbs.csv"'
logger.info("-- Getting ProcessDataDB History databases...")
os.system(sqlcmd)
# get list of historic databases
df = pd.read_csv(f"./data/{site}_dbs.csv")
logger.info(f"Found {len(df.index)} history DBs.\n")
# create list of DBs
list_of_dbs = list(df.Database)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment