mysql 将一个表中的数据复制到另一个表中
Posted 晨港飞燕
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 将一个表中的数据复制到另一个表中相关的知识,希望对你有一定的参考价值。
使用SELECT INTO 语句复制一条数据到历史表中出现错误
Java报错:
StatementCallback; bad SQL grammar [SELECT * INTO staff_info_h FROM staff_info WHERE id='123456']; nested exception is java.sql.SQLSyntaxErrorException: Undeclared variable: staff_info_h"
SQL报错:
SELECT * INTO staff_info_h FROM staff_info WHERE id='123456'
> 1327 - Undeclared variable: staff_info_h
1。表结构相同的表,且在同一数据库(如,table1,table2)
Sql :insert into table1 select * from table2 (完全复制)
insert into table1 select distinct * from table2(不复制重复纪录)
insert into table1 select top 5 * from table2 (前五条纪录)
2。 不在同一数据库中(如,db1 table1,db2 table2)
sql: insert into db1..table1 select * from db2..table2 (完全复制)
insert into db1..table1 select distinct * from db2table2(不复制重复纪录)
insert into tdb1..able1 select top 5 * from db2table2 (前五条纪录)
select into from 和 insert into select 都是用来复制表
两者的主要区别为: select into from 要求目标表不存在,因为在插入时会自动创建;insert into select from 要求目标表存在。
参考:https://www.cnblogs.com/zrmw/p/10255160.html
以上是关于mysql 将一个表中的数据复制到另一个表中的主要内容,如果未能解决你的问题,请参考以下文章
如何根据 MySQL 中第三个表中存在的 id 将数据从一个表复制到另一个表?
将具有 LONG RAW 列的表中的数据从一个数据库复制到另一个数据库