国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > MySQL > 正文

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

2024-07-24 13:05:29
字體:
來源:轉載
供稿:網(wǎng)友

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

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

1、 表結構相同的表,且在同一數(shù)據(jù)庫(如,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、不在同一數(shù)據(jù)庫中(如,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的數(shù)據(jù)拷入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數(shù)據(jù)庫復制表數(shù)據(jù)

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

復制代碼 代碼如下:


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

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

第二個命令是講數(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 from sourceTable在mssql中支持,在mysql中不支持
insert into desTable select * from sourceTable

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 庆云县| 新绛县| 普宁市| 太仓市| 舟曲县| 盐山县| 昌宁县| 金堂县| 永川市| 梓潼县| 金秀| 衡水市| 东至县| 全南县| 修文县| 运城市| 峨边| 洛隆县| 永福县| 上林县| 定襄县| 正安县| 博客| 鹿邑县| 施秉县| 沁阳市| 永寿县| 丰宁| 承德市| 威信县| 宝鸡市| 雷山县| 常宁市| 大庆市| 专栏| 嘉定区| 丹棱县| 合水县| 金乡县| 潼关县| 旬阳县|