日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 跨库复制_Mysql跨数据库(在同一IP地址中)复制表

發(fā)布時間:2023/12/15 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 跨库复制_Mysql跨数据库(在同一IP地址中)复制表 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

數(shù)據(jù)庫表間數(shù)據(jù)復制分類

在利用數(shù)據(jù)庫開發(fā)時,常常會將一些表之間的數(shù)據(jù)互相導入。當然可以編寫程序?qū)崿F(xiàn),但是,程序常常需要開發(fā)環(huán)境,不方便。最方便是利用sql語言直接導入。既方便而修改也簡單。以下就是導入的方法。1、 表結(jié)構(gòu)相同的表,且在同一數(shù)據(jù)庫(如,table1,table2)

Sql :insert into table1 select * fromtable2 (完全復制)insert into table1 select distinct * fromtable2(不復制重復紀錄)insert into table1 select top 5 * fromtable2 (前五條紀錄)2、 不在同一數(shù)據(jù)庫中(如,db1 table1,db2 table2)

sql:insert into db1.table1 select * fromdb2.table2 (完全復制)insert into db1.table1 select distinct * fromdb2table2(不復制重復紀錄)insert into tdb1.able1 select top 5 * fromdb2table2 (前五條紀錄)3、 表結(jié)構(gòu)不同的表或復制部分紀錄(如,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的數(shù)據(jù)拷入dn_usertemp

sql:insert into dn_usertemp select * fromdn_user2

c.將dn_usertemp 拷入dn_user

sql:declare @i int

declare @j int

declare @Namefntypeset @i=1

select @j=count(*) fromdn_usertempwhile @i

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

endMySql數(shù)據(jù)庫復制表數(shù)據(jù)

將 production 數(shù)據(jù)庫中的 mytbl 表快速復制為 mytbl_new,2個命令如下:CREATE TABLE mytbl_new LIKEproduction.mytbl;INSERT mytbl_new SELECT * FROMproduction.mytbl;

第一個命令是創(chuàng)建新的數(shù)據(jù)表 mytbl_new ,并復制 mytbl 的數(shù)據(jù)表結(jié)構(gòu)。

第二個命令是講數(shù)據(jù)表 mytbl 中的數(shù)據(jù)復制到新表 mytbl_new 。

注:production.mytbl是指定要復制表的數(shù)據(jù)庫名稱為 production 。它是可選的。

假如沒有production. ,MySQL數(shù)據(jù)庫將會假設mytbl在當前操作的數(shù)據(jù)庫。

另外:在mysql數(shù)據(jù)庫中復制數(shù)據(jù)為:select * into desTable fromsourceTable在mssql中支持,在mysql中不支持insert into desTable select * from sourceTable

總結(jié)

以上是生活随笔為你收集整理的mysql 跨库复制_Mysql跨数据库(在同一IP地址中)复制表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。