Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyodbc
- import sqlalchemy
- import snowflake.connector
- driver = 'SQL Server'
- server = 'tanmay'
- db1 = 'testing'
- tcon = 'no'
- uname = 'sa'
- pword = '123'
- cnxn = pyodbc.connect(driver='{SQL Server}',
- host=server, database=db1, trusted_connection=tcon,
- user=uname, password=pword)
- cursor = cnxn.cursor()
- cursor.execute("select * from Admin_tbldbbackupdetails")
- rows = cursor.fetchall()
- for row in rows:
- #data = [(id.row[0],dbname.row[1],dbpath.row[2], backupdate.row[3],backuptime.row[4], backupStatus.row[5],FaildMsg.row[6], Backupsource.row[7])]
- print (row)
- connection = snowflake.connector.connect(user='?',password='?',account='?')
- cursor2 = connection.cursor()
- #cursor2.execute("drop table sales.JFC_CHINA_RND.Admin_tbldbbackupdetails")
- cursor2.execute("CREATE OR REPLACE TABLE sales.JFC_CHINA_RND.Admin_tbldbbackupdetails_444 (id int, dbname varchar, dbpath varchar, backupdate datetime ,backuptime varchar,backupStatus int, FaildMsg varchar, Backupsource varchar)")
- cursor2.execute("begin")
- cursor2.execute("USE WAREHOUSE JOLLIBEE_WH")
- cursor2.execute("USE DATABASE Sales")
- #sql1="INSERT INTO JFC_CHINA_RND.Admin_tbldbbackupdetails_ip (id, dbname, dbpath, backupdate, backuptime, backupStatus, FaildMsg, Backupsource) select id, dbname, dbpath,backupdate,backuptime,backupStatus, FaildMsg, Backupsource from ")
- cursor2.execute("INSERT INTO connection.JOLLIBEE_WH.sales.JFC_CHINA_RND.Admin_tbldbbackupdetails_444 (id, dbname, dbpath, backupdate, backuptime, backupStatus, FaildMsg, Backupsource) select * from cnxn.testing.dbo.Admin_tbldbbackupdetails")
- #connection.cursor().execute("insert into sales.JFC_CHINA.Admin_tbldbbackupdetails_ip select * from dbo.Admin_tbldbbackupdetails")
- #cursor2.execute(sql)
- # rows = cursor2.fetchall()
- # for row in rows:
- # print (row)
- connection.commit()
- connection.close()
- cnxn.commit()
- cnxn.close()
- where,
- sales-database name
- jfc_china_rnd-schema
- cnxn-connection of sql server database
- testing-database name
- dbo-schema.
Add Comment
Please, Sign In to add comment