欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mysql跨數(shù)據(jù)庫復(fù)制表(在同一IP地址中)示例

 更新時(shí)間:2014年03月03日 16:28:27   作者:  
這篇文章主要介紹了mysql跨數(shù)據(jù)庫復(fù)制表(在同一IP地址中)示例,需要的朋友可以參考下

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

在利用數(shù)據(jù)庫開發(fā)時(shí),常常會(huì)將一些表之間的數(shù)據(jù)互相導(dǎo)入。當(dāng)然可以編寫程序?qū)崿F(xiàn),但是,程序常常需要開發(fā)環(huán)境,不方便。最方便是利用sql語言直接導(dǎo)入。既方便而修改也簡單。以下就是導(dǎo)入的方法。

1、 表結(jié)構(gòu)相同的表,且在同一數(shù)據(jù)庫(如,table1,table2)

Sql :

復(fù)制代碼 代碼如下:

insert into table1 select   *    from table2 (完全復(fù)制)
insert into table1 select   distinct   *   from table2(不復(fù)制重復(fù)紀(jì)錄)
insert into table1 select   top 5 *   from   table2 (前五條紀(jì)錄)

2、不在同一數(shù)據(jù)庫中(如,db1 table1,db2 table2)

sql:       
[code]
insert into db1.table1 select   *    from db2.table2 (完全復(fù)制)
insert into db1.table1 select   distinct   *   from db2table2(不復(fù)制重復(fù)紀(jì)錄)
insert into tdb1.able1 select   top 5 *   from   db2table2 (前五條紀(jì)錄)

3、表結(jié)構(gòu)不同的表或復(fù)制部分紀(jì)錄(如,dn_user,dn_user2)

a.  建一個(gè)新表[DN_UserTemp](在老表dn_user上增加一列)

復(fù)制代碼 代碼如下:

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 * from dn_user2

c.將dn_usertemp 拷入dn_user

sql:

復(fù)制代碼 代碼如下:

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數(shù)據(jù)庫復(fù)制表數(shù)據(jù)

將 production 數(shù)據(jù)庫中的 mytbl 表快速復(fù)制為 mytbl_new,2個(gè)命令如下:

復(fù)制代碼 代碼如下:

CREATE TABLE mytbl_new LIKE production.mytbl;
INSERT mytbl_new SELECT * FROM production.mytbl;

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

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

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

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

另外:在mysql數(shù)據(jù)庫中復(fù)制數(shù)據(jù)為:

復(fù)制代碼 代碼如下:

select * into desTable from sourceTable在mssql中支持,在mysql中不支持
insert into desTable select * from sourceTable

相關(guān)文章

  • MYSQL 5.6 從庫復(fù)制的部署和監(jiān)控的實(shí)現(xiàn)

    MYSQL 5.6 從庫復(fù)制的部署和監(jiān)控的實(shí)現(xiàn)

    這篇文章主要介紹了MYSQL 5.6 從庫復(fù)制的部署和監(jiān)控的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • MySQL中隔離級(jí)別RC與RR的區(qū)別及說明

    MySQL中隔離級(jí)別RC與RR的區(qū)別及說明

    這篇文章主要介紹了MySQL中隔離級(jí)別RC與RR的區(qū)別及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Mysql實(shí)現(xiàn)遞歸樹查詢的使用示例

    Mysql實(shí)現(xiàn)遞歸樹查詢的使用示例

    Mysql我們可以使用遞歸查詢來構(gòu)建一個(gè)遞歸樹,本文就來介紹一下Mysql實(shí)現(xiàn)遞歸樹查詢的使用示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • mysql查看表結(jié)構(gòu)的三種方法總結(jié)

    mysql查看表結(jié)構(gòu)的三種方法總結(jié)

    這篇文章主要介紹了mysql查看表結(jié)構(gòu)的三種方法總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • 定時(shí)備份mysql, 定時(shí)切割nginx access log的方法

    定時(shí)備份mysql, 定時(shí)切割nginx access log的方法

    定時(shí)備份mysql, 定時(shí)切割nginx access log的方法,需要的朋友可以參考下。
    2011-09-09
  • xampp修改mysql默認(rèn)密碼的方法

    xampp修改mysql默認(rèn)密碼的方法

    在這里介紹xampp修改mysql默認(rèn)密碼的大概過程是先利用xampp的phpmyadmin進(jìn)入修改mysql密碼,修改之后我們?cè)傩薷膞ampp中phpmyadmin的密碼,這樣就完整的修改mysql默認(rèn)密碼了,感興趣的朋友一起通過本文學(xué)習(xí)吧
    2016-10-10
  • MYSQL刪除重復(fù)數(shù)據(jù)的簡單方法

    MYSQL刪除重復(fù)數(shù)據(jù)的簡單方法

    業(yè)務(wù)中遇到要從表里刪除重復(fù)數(shù)據(jù)的需求,使用了下面的方法,執(zhí)行成功,大家可以參考使用
    2013-11-11
  • 最新評(píng)論