简体   繁体   English

如何将数据从一个表插入到另一个表?

[英]How to insert data from one table into another table?

I'm new to python and I was trying to insert data from one table to another and the code is executing but it is not reflecting any changes in new table in which I want to insert data. 我是python的新手,我试图将数据从一个表插入到另一个表中,并且代码正在执行,但是它没有反映我要在其中插入数据的新表中的任何更改。

import mysql.connector
conn=mysql.connector.connect(user='root',password='',host='localhost',database='xyz')
mycursor=conn.cursor()
mycursor.execute("insert into newTable select * from oldTable  group by mac,date,time order by mac")

您需要添加commit()进行更改。

conn.commit()

I suppose it is because you are not committing the changes. 我想这是因为您没有提交更改。 Use the below code and see if it works. 使用下面的代码,看看它是否有效。

conn.commit()

You need to use conn because that is the variable name for your connection to the database. 您需要使用conn,因为那是您与数据库连接的变量名。 A commit must be sent to the server, which in turn will commit your changes. 必须将提交发送到服务器,然后服务器将提交您的更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python sqlite 如何使用代码中的附加数据将一行中的一些数据插入到另一张表中 - python sqlite how to insert some data from one row into another table with additional data from code 将大量数据从一个表插入到另一个 MySQL Python - Insert bulk of data from one table to another MySQL Python 如何使用多重处理将数据从一个数据库表有效插入另一个表? - How to effectively insert data from one database table to another using multiprocessing? 如何使用 SQLAlchemy ORM 使用子查询进行插入(将数据从一个表移动到另一个表) - How do I use the SQLAlchemy ORM to do an insert with a subquery (moving data from one table to another) 如何将一个表的ID插入另一个表? - How do I insert an id from one table to another? 插入到通过 FOREIGN KEY 链接到第二个表的 2 个表中,并从 sqlite 和 python 中的另一个表中获取数据 - insert into 2 table one linked to the second through FOREIGN KEY and take data from another table in sqlite and python 如何从一个表中选择 id 并插入/更新到另一个表 - How to select id's from one table and insert/update to another table 从一个表中选择另一个表中具有相似数据的数据 - Choosing data from one Table that have similar data in another table 将表数据从一个DB复制到另一个DB - Copy Table data from one DB to another 将数据从一个表映射到另一个表? - Mapping Data from one table to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM