pymysql批量更新資料
使用python更新資料
使用指令碼執行資料顯得更慢,資料的可操作性要好一些,可以對資料進行處理;
import pymysql
connection = pymysql.connect("127.0.0.1", "alvin2", "123456", "podata")
try:
with connection.cursor() as cursor:
# Read a single record
# 查詢需要更新的資料,左連結查出關聯表的資料
sql = """SELECT b.`emp_family_name`, b.`emp_first_name`, b.`email_suffix`, b.`emp_position`, b.`birthday`, b.`hire_date`, b.`domainacc`, b.`emp_fire_date`, b.`phfloc`, b.`phflocdescr`, b.`socloc`, b.`soclocdescr`,b.`prc_dt`,b.`exp_prc_dt_end`,b.`workcitycode`,b.`bu`,b.`budescr`, b.`contractloc`, b.`contractlocdescr`, b.`eid`
FROM hris_employee AS a LEFT JOIN hris_employee_20201222 AS b
ON a.`eid` = b.`eid`"""
cursor.execute(sql)
result = cursor.fetchall()
# 需要批量更新的sql
updatesql = "update hris_employee set emp_family_name=(%s), emp_first_name=(%s), email_suffix=(%s), emp_position=(%s), birthday=(%s), hire_date=(%s), domainacc=(%s), emp_fire_date=(%s), phfloc=(%s), phflocdescr=(%s), socloc=(%s), soclocdescr=(%s), prc_dt=(%s), exp_prc_dt_end=(%s), workcitycode=(%s), bu=(%s), budescr=(%s), contractloc=(%s), contractlocdescr=(%s) where eid=(%s)"
cursor.executemany(updatesql, result)
print('執行完成')
finally:
connection.close()
使用sql 直接更新資料
UPDATE `hris_employee` AS a LEFT JOIN `hris_employee_20201222` AS b
ON a.`eid`=b.`eid`
SET a.`emp_family_name` = b.`emp_family_name`,
a.`emp_first_name` = b.`emp_first_name`,
a.`email_suffix` = b.`email_suffix`,
a.`emp_position` = b.`emp_position`,
a.`birthday` = b.`birthday`,
a.`hire_date` = b.`hire_date`,
a.`domainacc` = b.`domainacc`,
a.`emp_fire_date` = b.`emp_fire_date`
相關文章
- 如何批量更新資料
- 資料庫-批量更新資料庫
- oracle批量新增更新資料Oracle
- 海量資料處理_批量更新
- Ibatis批量更新資料(mysql資料庫)BATMySql資料庫
- (資料庫之pymysql)資料庫MySql
- 批量更新資料方法比較測試
- MySQL 批量更新、刪除資料shell指令碼MySql指令碼
- ibatis對oracle資料庫的批量更新和批量插入的操作BATOracle資料庫
- MySQL NDB 批量更新100萬行資料MySql
- 【oracle】更新大批量資料變更步驟Oracle
- mysql根據查詢結果批量更新多條資料(插入或更新)MySql
- SQLServer批量更新SQLServer
- Laravel 批量更新Laravel
- Django使用pymysql連線MySQL資料庫DjangoMySql資料庫
- python資料庫操作 - PyMySQL入門Python資料庫MySql
- 批量更新SQL Server資料庫的使用者檢視SQLServer資料庫
- 利用rowid 進行大批量資料更新 -- 轉帖
- python操作MySQL資料庫連線(pymysql)PythonMySql資料庫
- 批量更新總結
- 批量更新的陷阱?
- Dynamics CRM 如何使用XrmToolBox中的Bulk Workflow Execution批量更新資料
- 【python介面自動化】- PyMySQL資料連線PythonMySql
- 【Python】基於pymysql的資料庫操作類PythonMySql資料庫
- mybatis插入資料、批量插入資料MyBatis
- indexedDB 批量新增資料Index
- oracle批量插入資料Oracle
- MyBatis 批量插入資料MyBatis
- 批量更新效能比較
- Python 利用pymysql和openpyxl操作MySQL資料庫並插入Excel資料PythonMySql資料庫Excel
- PymysqlMySql
- python3使用PyMysql連線mysql資料庫PythonMySql資料庫
- 資料庫死鎖導致分佈事務中大批量更新資料庫不成功資料庫
- 批量下載SRR資料
- SQLServer批量新增資料庫SQLServer資料庫
- Mybatis批量更新三種方式MyBatis
- iOS FMDB 查詢 批量更新iOS
- 一句sql,批量更新SQL