Guest User

Untitled

a guest
Jul 13th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import pyodbc
  2. import sqlalchemy
  3. import snowflake.connector
  4. driver = 'SQL Server'
  5. server = 'tanmay'
  6. db1 = 'testing'
  7. tcon = 'no'
  8. uname = 'sa'
  9. pword = '123'
  10.  
  11. cnxn = pyodbc.connect(driver='{SQL Server}',
  12. host=server, database=db1, trusted_connection=tcon,
  13. user=uname, password=pword)
  14. cursor = cnxn.cursor()
  15. cursor.execute("select * from Admin_tbldbbackupdetails")
  16. rows = cursor.fetchall()
  17. for row in rows:
  18. #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])]
  19. print (row)
  20.  
  21.  
  22.  
  23.  
  24.  
  25. connection = snowflake.connector.connect(user='?',password='?',account='?')
  26.  
  27. cursor2 = connection.cursor()
  28. #cursor2.execute("drop table sales.JFC_CHINA_RND.Admin_tbldbbackupdetails")
  29.  
  30. 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)")
  31.  
  32. cursor2.execute("begin")
  33. cursor2.execute("USE WAREHOUSE JOLLIBEE_WH")
  34. cursor2.execute("USE DATABASE Sales")
  35. #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 ")
  36. 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")
  37.  
  38. #connection.cursor().execute("insert into sales.JFC_CHINA.Admin_tbldbbackupdetails_ip select * from dbo.Admin_tbldbbackupdetails")
  39. #cursor2.execute(sql)
  40. # rows = cursor2.fetchall()
  41. # for row in rows:
  42. # print (row)
  43.  
  44. connection.commit()
  45. connection.close()
  46. cnxn.commit()
  47. cnxn.close()
  48.  
  49.  
  50.  
  51.  
  52. where,
  53. sales-database name
  54. jfc_china_rnd-schema
  55. cnxn-connection of sql server database
  56. testing-database name
  57. dbo-schema.
Add Comment
Please, Sign In to add comment