DB2複製表結構及資料

2022-08-26 07:57:07 字數 1032 閱讀 1462

在db2資料庫中,複製已經存在的表的結構及其資料。我們採用兩步走方式:第一步先複製表結構,第二部拷貝資料。

第一步:複製表結構

方法一:

create

table test_rate as

(select

*from t_rate) definition only;--

test_rate是新錶,t_rate是老表

方法二:

create

table test_rate like

t_rate;

--test_rate 是新錶,t_rate是老表

說明:上述方式建立的新錶不複製老表的主鍵,約束,索引,非空,預設值,資料。且建立的新錶放在使用者的臨時表空間中。

/*

----查詢新錶test_rate的主鍵,表空間----

*/select keycolumns,keyindexid,tbspace from syscat.tables where tabname=

'test_rate'--

keycolumns:表示有幾個字段組成聯合主鍵,

keyindexid:等於0表示沒有主鍵

/*----查詢新錶test_rate的索引----

*/select

*from syscat.indexes where tabname=

'test_rate';

--上述查詢有記錄表示表有索引,反之沒有

/*----查詢新錶test_rate的記錄條數----

*/select

count(1) from test_rate

第二步:插入資料

insert

into test_rate select

*from t_rate where'條件

';

通過以上操作,會拷貝t_rate的表結構及資料至test_rate表上。

oracle複製表資料,複製表結構

1.不同使用者之間的表資料複製 對於在乙個資料庫上的兩個使用者a和b,假如需要把a下表old的資料複製到b下的new,請使用許可權足夠的使用者登入sqlplus insert into b.new select from a.old 如果需要加條件限制,比如複製當天的a.old資料 insert i...

mysql複製表資料 MySQL 複製表結構

介紹 有時候我們需要原封不動的複製一張表的表結構來生成一張新錶,mysql提供了兩種便捷的方法。例 create tabletb base idint not null primary key,namevarchar 10 keyix name name engine myisam charset ...

oracle 複製表結構及表資料

1 複製表結構以及資料 create table d table name as select from s table name 注意並不會建立索引 2 只複製表結構 create table d table name as select from s table name where 1 2 3...