當前位置:首頁 » 編程語言 » db2sql復制技術
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

db2sql復制技術

發布時間: 2023-01-02 18:21:19

① IBM DB2 的數據復制、遷移方法[1]

以下方法經測試 在環境IBM x G× G RAID DB V Win Adv Server DMS表空間中 數據的load速度在 萬條/min左右

背景 需要更改資料庫表空間 或者需要將資料庫中所有表的數據遷移到一個新的資料庫中

步驟

通過db 控制台(db cc)選中源資料庫中的所有表 將其導出成DDL腳本;

根據需要對腳本進行必要的修改 譬如更改表空間為GATHER;

新建資料庫 新建DMS表空間:GATHER;

將DDL腳本在此資料庫中執行;

編寫代碼查詢源資料庫中的所有表 自動生成export腳本;

編寫代碼查詢源資料庫中的所有表 自動生成import腳本;

連接源資料庫執行export腳本;

連接目標資料庫執行import腳本;

附錄 :生成export腳本代碼示例:/*** 創建導出腳本

* @param conn

* @param creator表創建者

* @param filePath

*/

public void createExportFile(Connection conn String creator String filePath) throws Exception {

DBBase dbBase = new DBBase(conn);

String selectTablesql = select name from sysibm systables where creator = + creator + and type= T ;

try {

dbBase executeQuery(selectTableSql);

} catch (Exception ex) {

throw ex;

} finally {

dbBase close();

}

DBResult result = dbBase getSelectDBResult();

List list = new ArrayList();

while (result next()) {

String table = result getString( );

list add(table);

}

StringBuffer *** = new StringBuffer();

String enterFlag = ;

for (int i = ; i < list size();i++) {

String tableName = (String)list get(i);

*** append( db export to aa + String valueOf(i+ )+ ixf of ixf select * from + tableName + );

lishixin/Article/program/DB2/201311/21944

② 如何將DB2數據導入到SQLSERVER中

int inthestr(char *s,char ch)
{
while(*s!='\0'){
if(*s==ch)
return 1;
s++;
}
return 0;
}

③ DB2的復制遷移

以下方法經測試,在環境IBM x346,3.2G×2,4G,RAID 1,DB2 V8.2.4,Win2000 Adv Server,DMS表空間中,數據的load速度在60-100萬條/min左右。
背景:需要更改資料庫表空間,或者需要將資料庫中所有表的數據遷移到一個新的資料庫中。
步驟:
1.通過db2控制台(db2cc)選中源資料庫中的所有表,將其導出成DDL腳本;
2.根據需要對腳本進行必要的修改,譬如更改表空間為GATHER;
3.新建資料庫,新建DMS表空間:GATHER;
4.將DDL腳本在此資料庫中執行;
5.編寫代碼查詢源資料庫中的所有表,自動生成export腳本;
6.編寫代碼查詢源資料庫中的所有表,自動生成import腳本;
7.連接源資料庫執行export腳本;
8.連接目標資料庫執行import腳本;
附錄1:生成export腳本代碼示例:/**
* 創建導出腳本* @param conn
* @param creator表創建者
* @param filePath
*/
public void createExportFile(Connection conn,String creator,String filePath) throws Exception {
DBBase dbBase = new DBBase(conn);
String selectTableSql 2= select name from sysibm.systables where creator = ' + creator + ' and type='T';
try {
dbBase.executeQuery(selectTableSql2);
} catch (Exception ex) {
throw ex;
} finally {
dbBase.close();
}
DBResult result = dbBase.getSelectDBResult();
List list = new ArrayList();
while (result.next()) {
String table = result.getString(1);
list.add(table);
}
StringBuffer sb = new StringBuffer();
String enterFlag = ;
for (int i = 0; i < list.size();i++) {
String tableName = (String)list.get(i);
sb.append(db2 export to aa + String.valueOf(i+1)+ .ixf of ixf select * from + tableName + );
sb.append(enterFlag);
}
String str = sb.toString();
FileUtility.saveStringToFile(filePath, str, false);
}附錄2:生成import腳本代碼示例:/**
* 創建裝載腳本
* @param conn
* @param creator表創建者
* @param filePath
*/
public void createLoadFile(Connection conn,String creator,String filePath) throws Exception {
DBBase dbBase = new DBBase(conn);
String selectTableSql = select name from sysibm.systables where creator = ' + creator + ' and type='T';
try {
dbBase.executeQuery(selectTableSql);
} catch (Exception ex) {
throw ex;
} finally {
dbBase.close();
}
DBResult result = dbBase.getSelectDBResult();
List list = new ArrayList();
while (result.next()) {
String table = result.getString(1);
list.add(table);
}
StringBuffer sb = new StringBuffer();
String enterFlag = ;
for (int i = 0; i < list.size();i++) {
String tableName = (String)list.get(i);
sb.append(db2 load from aa + String.valueOf(i+1)+ .ixf of ixf into + tableName + COPY NO without prompting );
sb.append(enterFlag);
}
String str = sb.toString();
FileUtility.saveStringToFile(filePath, str, false);
}附錄3:export腳本示例db2 connect to testdb user test password test
db2 export to aa1.ixf of ixf select * from table1
db2 export to aa2.ixf of ixf select * from table2
db2 connect reset附錄4:import腳本示例db2 connect to testdb user test password test
db2 load from aa1.ixf of ixf replace into table1 COPY NO without prompting
db2 load from aa2.ixf of ixf replace into table2 COPY NO without prompting
db2 connect reset

④ SQL Server 2000 ,如何將一個資料庫中的表結構復制到另外一個資料庫中

操作方案:將db2復製成db1,將原db1中的數據導入即可。

1、分離db1、db2。
2、將db2資料庫文件復制一份存成另外的名。
3、將db2存成另外名的文件附加為資料庫db1,並將所有用戶表數據清空。
4、將db1的文件附加成資料庫db3,將db3中的數據導入db1。

⑤ 如何把DB2的數據直接導入SQL server中

1、在SQL Server中,在對應的資料庫中點擊右鍵然後選擇「任務」菜單下的「生成腳本」,連續點擊兩個「下一步」
2、在彈出的對話框中,在「選項」下面的框中找到「為伺服器版本編寫腳本」
3、把SQL Server修改成SQL Server 2000,然後再點擊下一步,把表選中,如有存儲過程,也需要把存儲過程選中,然後點擊下一步
4、全選存儲過程或者表,然後點擊「下一步」,再點擊「完成」
5、在新建的查詢窗口中生成了所有的SQL語句,把這些語句進行復制,然後在SQL Server 2000中對應資料庫的查詢分析器中進行執行,就把對應的表結構及存儲過程生成了。
6、再用SQL Server 2000中在對應資料庫中點擊右鍵,在「所有任務」對應的「導入數據」,輸入SQL Server 2005中伺服器的名稱或者IP地址
7、輸入SQL Server 2000中伺服器對應的名稱或者IP地址,然後默認的選擇進入「下一步」,全選所有的表,然後點擊兩個「下一步「,數據就可以導進來了。

⑥ sql中如何把一個資料庫裡面的數據復制到第二個裡面去

要復制某個表:
insert
into
目標表名
select
*
from
[ip地址].[資料庫名].dbo.源表名
要復制整個資料庫最簡單的就是從
企業管理器
中備份一個源資料庫
再還原到目標資料庫
也可以用「導出數據功能」

⑦ 資料庫B無表,如何復制sql資料庫A表到資料庫B

是不是oracle資料庫?如果是的你可以用命令。
用法:
from
資料庫1的用戶名/資料庫1的密碼@資料庫1的名稱
insert
into
a(a1,a2,a3,a4)
using
select
b1,b2,b3,b4
from
b;
代碼在資料庫2執行。
如你有資料庫db1,db2(假設用戶名和密碼為scott,tiger),要從db2把數據復制到db1.

from
scott/tiger@db2
insert
into
a(a1,a2,a3,a4)
using
select
b1,b2,b3,b4
from
b;

⑧ 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資料庫復製表數據

將 proction 資料庫中的 mytbl 錶快速復制為 mytbl_new,2個命令如下:

復制代碼代碼如下:

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

第一個命令是創建新的數據表 mytbl_new ,並復制 mytbl 的數據表結構。
第二個命令是講數據表 mytbl 中的數據復制到新表 mytbl_new 。
註:proction.mytbl是指定要復製表的資料庫名稱為 proction 。它是可選的。
假如沒有proction. ,MySQL資料庫將會假設mytbl在當前操作的資料庫。
另外:在mysql資料庫中復制數據為:

復制代碼代碼如下:

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

⑨ DB2資料庫,將表A中的數據復制到表B中,如何寫SQL

1、欄位要匹配(數量、類型);

INSERTINTOB(ID--逐一列出,避免對應不上
,...
)
SELECTID--需要新ID的話,換成自己的函數或者計算公式
,...
FROMA

2、若ID欄位是自增長的,要將自增長屬性關閉