
正文
关于mysql同个表怎么复制的信息
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
怎么把mysql一张表复制所有数据
一、复制表里面的一条记录并插入表里面
① insert into article(title,keywords,desc,contents) select title,keywords,desc,contents from article where article_id = 100;
二、复制表里的多条数据/记录mysql同个表怎么复制,并插入到表里面
① INSERT INTO `power_node`(title,type,status) SELECT title,type,status FROM power_node WHERE id 5;
② INSERT into jiaban (num,overtime) SELECT num,overtime from jiaban where id IN(1,3,5,6,7,9);
三、在创建表时mysql同个表怎么复制,就插入另一张表里面的某些数据
① create table user AS select * from member where id 10
相关问答
Q1: mysql如何复制数据到同一张表?
在利用数据库开发时,常常会将一些表之间的数据互相导入。当然可以编写程序实现,但是,程序常常需要开发环境,不方便。最方便是利用sql语言直接导入。既方便而修改也简单。以下就是导入的方法。
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:
[code]
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 (前五条纪录)
3、表结构不同的表或复制部分纪录(如,dn_user,dn_user2)
a. 建一个新表[DN_UserTemp](在老表dn_user上增加一列)
复制代码代码如下:
CREATE TABLE [DN_UserTemp] ( [Num] [numeric](18, 0) IDENTITY (1, 1) NOT NULL)
[Id] [idtype] NOT NULL ,
[Name] [fntype] NOT NULL ,
[Descript] [dstype] NULL ,
[LogonNm] [idtype] NOT NULL ,
[Password] [idtype] NULL ,
[Gender] [char] (1) NULL ,
[Quited] [booltype] NOT NULL,
[OffDuty] [booltype] NOT NULL ,
[Stopped] [booltype] NOT NULL,
[OSBind] [booltype] NOT NULL,
[Domain] [idtype] NULL ,
[EMail] [fntype] NULL ,
[UnitId] [idtype] NULL ,
[BranchId] [idtype] NULL ,
[DutyId] [idtype] NULL ,
[LevelId] [idtype] NULL ,
[ClassId] [idtype] NULL ,
[TypeId] [idtype] NULL ,
[IP] [varchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
[ExpireDT] [datetime] NULL ,
[Sort] [int] NOT NULL ,
[AllowDel] [booltype] NOT NULL,
[UnitChief] [booltype] NOT NULL,
[BranchChief] [booltype] NOT NULL ,
[UnitDeputy] [booltype] NOT NULL ,
[BranchDeputy] [booltype] NOT NULL ,
[Num] [numeric](18, 0) IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
b. 将dn_uer2的数据拷入dn_usertemp
sql:insert into dn_usertemp select * from dn_user2
c.将dn_usertemp 拷入dn_user
sql:
复制代码代码如下:
declare @i int
declare @j int
declare @Name fntype
set @i=1
select @j=count(*) from dn_usertemp
while @i@j 1
begin
select @Name=Name from dn_usertemp where Num=@i
print @Name
insert into dn_user (Name) values (@Name) where Num=@i
select @i=@i 1
end
MySql数据库复制表数据
将 production 数据库中的 mytbl 表快速复制为 mytbl_new,2个命令如下:
复制代码代码如下:
CREATE TABLE mytbl_new LIKE production.mytbl;
INSERT mytbl_new SELECT * FROM production.mytbl;
第一个命令是创建新的数据表 mytbl_new ,并复制 mytbl 的数据表结构。
第二个命令是讲数据表 mytbl 中的数据复制到新表 mytbl_new 。
注:production.mytbl是指定要复制表的数据库名称为 production 。它是可选的。
假如没有production. ,MySQL数据库将会假设mytbl在当前操作的数据库。
另外:在mysql数据库中复制数据为:
复制代码代码如下:
select * into desTable from sourceTable在mssql中支持,在mysql中不支持
insert into desTable select * from sourceTable
Q2: 如何复制MySQL数据库或表到另外一台服务器?
使用这种方法前,我们需要先下载一个MySQL客户端工具SqlYog。点击这里下载并安装\x0d\x0a\x0d\x0a下面我们开始复制数据库:\x0d\x0a1、打开SqlYog community Edition,分别在不同的选项卡中打开源数据库服务器与目标数据库服务器,这一点很重。\x0d\x0a\x0d\x0a在源数据库服务器选项卡中你将看到所有数据库列表。\x0d\x0a2、在需要复制迁移的数据库上右击,在弹出菜单中选择“Copy Database to Different Host/Database”\x0d\x0a3、在弹出对话框中,我们能看到源数据库服务器及目标服务器,在左边,通过勾选复选框来选择需要复制迁移的对象,如表、函数、触发器等,也可以选择所有对象。\x0d\x0a4、在右边选择需要迁移的目标服务器或数据库\x0d\x0a5、根据你的需要选择复制类型:“Structure and Data”或“Structure only”,即“结构和数据”或“仅结构”。\x0d\x0a6、选择结束后点击“Copy”按钮开始复制,知道数据迁移结束。
mysql同个表怎么复制的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、mysql同个表怎么复制的信息别忘了在本站进行查找喔。








