導航:首頁 > 程序命令 > db2命令建表

db2命令建表

發布時間:2023-01-03 00:27:43

① DB2資料庫在linux操作系統的指令有哪些

DB2資料庫命令簡介 1.啟動資料庫 DB2start 2.停止資料庫 DB2stop DB2資料庫在linux相關指令之3.連接資料庫 DB2 connect to o_yd user DB2 using pwd 4.讀資料庫管理程序配置 DB2 get dbm cfg 5.寫資料庫管理程序配置 DB2 update dbm cfg using 參數名 參數值 6.讀資料庫的配置 DB2 connect to o_yd user DB2 using pwd DB2 get db cfg for o_yd 7.寫資料庫的配置 DB2 connect to o_yd user DB2 using pwd DB2 update db cfg for o_yd using 參數名 參數值 8.關閉所有應用連接 DB2 force application all DB2 force application ID1,ID2,,,Idn MODE ASYNC (DB2 list application for db o_yd show detail) 9.備份資料庫 DB2 force application all DB2 backup db o_yd to d: (DB2 initialize tape on \.tape0) (DB2 rewind tape on \.tape0) DB2 backup db o_yd to \.tape0 10.恢復資料庫 DB2 restore db o_yd from d: to d: DB2 restore db o_yd from \.tape0 to d: DB2資料庫在linux相關指令之11.綁定存儲過程 DB2 connect to o_yd user DB2 using pwd DB2 bind c:dfplus.bnd 拷貝存儲過程到伺服器上的C:sqllibfunction目錄中 12.整理表 DB2 connect to o_yd user DB2 using pwd DB2 reorg table ydd DB2 runstats on table ydd with distribution and indexes all 13.導出表數據 DB2 export to c:dftz.txt of del select * from dftz DB2 export to c:dftz.ixf of ixf select * from dftz 14.導入表數據 import from c:123.txt of del insert into ylbx.czyxx DB2 import to c:dftz.txt of del commitcount 5000 messages c:dftz.msg insert into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 messages c:dftz.msg insert into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 insert into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 insert_update into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 replace into dftz DB2 import to c:dftz.ixf of ixf commitcount 5000 create into dftz (僅IXF) DB2 import to c:dftz.ixf of ixf commitcount 5000 replace_create into dftz (僅IXF) 15.執行一個批處理文件 DB2 -tf 批處理文件名 (文件中每一條命令用 ;結束) 16.自動生成批處理文件 建文本文件:temp.sql select 'runstats on table DB2.' || tabname || ' with distribution and detailed indexes all;' from syscat.tables where tabschema='DB2' and type='T'; DB2 -tf temp.sql>runstats.sql 17.自動生成建表(視圖)語句 在伺服器上:C:sqllibmisc目錄中 DB2 connect to o_yd user DB2 using pwd DB2look -d o_yd -u DB2 -e -p -c c:o_yd.txt DB2資料庫在linux相關指令之18.其他命令 grant dbadm on database to user bb 19select * from czyxx fetch first 1 rows only 20DB2look -d ylbx -u DB2admin -w -asd -a -e -o a.txt21. 顯示當前用戶所有表 list tables 22.列出所有的系統表 list tables for system 23.查看錶結構 DB2 describe select * from user.tables (實習編輯:HJ)

② db2 windows創建表空間文件路徑怎麼寫

在windows下,通過如下命令即可創建db2實例:db2icrt
instance_name
需要注意的是,instance_name必須按照如下的規則命令:
1)不能大於
8
個字元
2)不能
以"sql"、"ibm"或"sys"開頭
3)不能以數字開頭或者包含
a-z、$、#、@、_

0-9
之外的字元
如:以下是代碼片段:db2bin>db2icrt
insttest
db20000i
db2icrt命令成功完成。
d:db2bin>
要刪除一個實例,首先斷開所有資料庫連接,然後執行以下命令停止實例:以下是代碼片段:db2idrop
-f
instance_name
比如:以下是代碼片段:db2bin>db2idrop
-f
insttest
db20000i
db2idrop命令成功完成。
db2bin>
察看實例配置文件
--默認以下是代碼片段:db2
get
dbm
cfg
--分屏顯示以下是代碼片段:db2
get
dbm
cfg
|
more
--將顯示結果存入
cfg.out
文件中以下是代碼片段:db2
get
dbm
cfg
>
cfg.out

③ 如何在DB2建表空間

一、建表空間和資料庫
1.在db2ad、db2db和db2ap上均執行:

[sql] view plain
db2set db2comm=tcpip
db2set db2codepage=1386
2.新建資料庫:

[sql] view plain
db2 create db <dbname> using codeset gbk territory CN collate using identity
3.連接上資料庫:

[sql] view plain
db2 "connect to <dbname>"
4.創建緩沖池 + 建立表空間;
1).刪除舊的表空間:

[sql] view plain
db2 drop tablespace tablespace1, tablespace2, tablespace3
2).新建緩沖池:

[sql] view plain
db2 create bufferpool bp32k all nodes size -1 pagesize 32k
bp32k為該緩沖池的名稱;
32K為頁大小;
size=-1表示使用預設的buffpage,而buffpage可以通過db2 get db cfg|grep -i buff參數查看到;
3).新建表空間:

[sql] view plain
db2 "create regular tablespace tablespace1 pagesize 32k managed by database using(file '/usr/yixiayizi/tablespace1' 5g) bufferpool bp32k"
db2 "create regular tablespace tablespace2 pagesize 32k managed by database using(file '/usr/yixiayizi/tablespace2' 10g) bufferpool bp32k"
db2 "create regular tablespace tablespace3 pagesize 32k managed by database using(file '/usr/yixiayizi/tablespace3' 2g) bufferpool bp32k"
注意(file '/usr/yixiayizi/tablespace1' 5g)的設置:
第一個參數:
當指向外置盤時,file改為device;
當指向文件路徑時,為file;
第二個參數:需要是絕對路徑;
第三個參數:該表空間的大小;

關於表空間和緩沖池的說明見如下網頁:
http://www.ibm.com/developerworks/cn/data/library/techarticles/0212wieser/0212wieser.html

5.調整表空間大小:

[sql] view plain
ALTER TABLESPACE <tablespace1> RESIZE ( FILE '/cstp/usr/db2ad/db2ad/ <tablespace1>' 5g )
6.調整緩沖池大小:

[sql] view plain
db2 alter bufferpool bp32k size 2g
--------------------------------------------------------------------------------------------
遠程客戶端的配置網路:
1.db2ad賬戶下:
1). 首先查看/etc/services中db2各個服務的埠號:
more /etc/services
可以看到如下信息:
DB2_db2ad 60040/tcp
DB2_db2ad_1 60041/tcp
DB2_db2ad_2 60042/tcp
DB2_db2ad_END 60043/tcp
2).
[sql] view plain
db2 update dbm cfg using SVCENAME DB2_db2ad
這樣在服務端實例對應的埠號就是60040;
------------
2.db2db賬戶下:
1).
[sql] view plain
db2 catalog tcpip node <node_name> remote 172.17.252.214 server 60040
(上面操作的反編目:db2 uncatalog node <node_name>)
2).db2 list node directory可以看到如下信息:
Node Directory
Number of entries in the directory = 1
Node 1 entry:
Node name = <node_name>
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = 172.17.252.214
Service name = 60040

3).
[sql] view plain
db2 catalog db <dbname> at node <node_name>
(上面操作的反編目:db2 uncatalog db <dbname>)
4).db2 list db directory可以看到如下信息:
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = <dbname>
Database name = <dbname>
Node name = <node_name>
Database release level = c.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
--編目系統資料庫目錄
-----------------------
授權:
在db2ad賬戶下,給db2db授權使用表空間:

[sql] view plain
db2 "grant use of tablespace <tablespace1> to user db2db"
db2 "grant use of tablespace <tablespace2> to user db2db"
db2 "grant use of tablespace <tablespace3> to user db2db"
二、建表

切換到db2db用戶,執行建表的sql語句:
db2 -vf tmp.sql

④ DB2批量建表命令腳本在哪裡運行

start--->run-->db2cmd--->db2 -tvf <file_name.ddl>

t 的默認為ddl文件每一行以分號結束
選項 描述 當前設置
------ ---------------------------------------- ---------------
-a 顯示 SQLCA OFF
-c 自動落實 ON
-e 顯示 SQLCODE/SQLSTATE OFF
-f 讀取輸入文件 OFF
-l 將命令記錄到歷史文件中 OFF
-n 除去換行字元 OFF
-o 顯示輸出 ON
-p 顯示互動式輸入提示符 ON
-r 將輸出保存到報告文件 OFF
-s 在命令出錯時停止執行 OFF
-t 設置語句終止字元 OFF
-v 回送當前命令 OFF
-w 顯示 FETCH/SELECT 警告消息 ON
-x 不列印列標題 OFF
-z 將所有輸出保存到輸出文件 OFF

⑤ 哪位高手知道DB2的常用命令是什麼哦麻煩說一下,謝謝啦

1、db2 connect to <資料庫名> user <用戶名> using <密碼> --連接資料庫
2、 db2 force application all --強迫所有應用斷開資料庫連接
3、db2 backup db db2name<資料庫名稱> --備份整個資料庫數據
db2 restore db <db2name> --還原資料庫
4、db2 list application --查看所有連接(需要連接到具體資料庫才能查看)

5、db2start --啟動資料庫 ,db2stop --停止資料庫
6、create database <資料庫名> using codeset utf-8 territory CN --創建資料庫使用utf-8編碼
7、db2 catalog 命令
db2 catalog tcpip node <接點名稱> remote <遠程資料庫地址> server <埠號> --把遠程資料庫映射到本地接點一般為50000
db2 catalog db <遠程資料庫名稱> as <接點名稱> at node PUB11 --遠程資料庫名稱到本地接點
db2 CONNECT TO <接點名稱> user <用戶名> using <密碼> --連接本地接點訪問遠程資料庫
8、資料庫導出
db2look -d <資料庫名> -u <用戶> -e -o <腳本名稱>.sql --導出資料庫的表結構,其中用戶空間一般為db2admin/db2inst1
db2look -d <資料庫名> -u <用戶> -t <表1> <表2> -e -o <腳本名稱>.sql --導出資料庫中表1和表2的表結構
db2move <資料庫名> export --導出資料庫數據
db2move <資料庫名> export -tn <表1>,<表2> --導出資料庫中表和表數據

9、資料庫導入
db2 -tvf <腳本名稱>.sql --把上述導出的表結構導入到資料庫表結構
db2move <資料庫名> load -lo replace --把上述「db2move <資料庫名> export 「導出的數據導入到資料庫中並把相同的數據替換掉 在實際使用過程中,如果用到db2自增主鍵,需要使用by default, 而不是always,功能是一樣的,但這樣在數據移植時候會很方便!
10、db2 connect reset 或 db2 terminate --斷開與資料庫的連接
11、db2set db2codepage=1208 --修改頁編碼為1208
12、db2 describe table <表名> --查看錶結構(比較常用)
13、db2 list tables --查看資料庫中所有表結構(常用)
list tables for system --列出所有系統表
14、db2 list tablespaces --列出表空間
15、fetch first 10 rows only --列出表中前10條數據
例如:select * from <表名> fetch first 10 rows only
16、coalesce(欄位名,轉換後的值) --對是null的欄位進行值轉換
value(欄位名,轉換後的值) --對是null的欄位進行值轉換
例如:select coalesce(id,1) from <表名> --對表中id如果為null轉換成1
select value(id,1) from 表日)
17、concatt(參數1,連接值) --把參數1加上連接值組成一個新值。
例如:concat('aa','b') --返回是aab

18、create alise admin.tb_biao on tb_biao 創建 同義詞
19、查詢系統時間「
select current timestamp from sysibm.sysmmy1;
這些裡面有網上的有我自己整理的,希望對你有幫助!

⑥ db2的命令行處理器怎麼執行sql腳本文件建表

無論是windows系統,還是linux或AIX
你可以在實例用戶下,先鍵入 db2 這個命令,進入到db2命令行,然再執行creat database mydb

或者

你可以在系統命令行下直接執行
db2 create database mydb

db2 "create database mydb"

⑦ db2資料庫導出表結構

第一行是連接資料庫,後面就是具體的建表語句。 2、執行建表腳本 命令為: db2 –tvf f:\export\init.sql 1 以上是導出了資料庫中所有表的表結構,並在新的資料庫中執行命令,新建所有表。但是表中均是不存在數據的。

⑧ 如何在Windows CMD裡面用命令行操作DB2資料庫

1、打開電腦,進入電腦操作系統,點擊開始菜單,在電腦開始菜單中,找到命令行cmd,或者使用快捷鍵組合WIN+R鍵可以直接打開運行,輸入cmd命令行,即可直接打開命令行cmd。

⑨ db2建表語句主鍵最長是多少位

資料庫管理器中表的行長度不能超過:
* 在具有 4K 頁大小的表空間中,是 4005 位元組
* 在具有 8K 頁大小的表空間中,是 8101 位元組。
* 在具有 16K 頁大小的表空間中,是 16293 位元組。
* 在具有 32K 頁大小的表空間中,是 32677 位元組。

這個是DB2的硬限制,USERSPACE1是默認創建的4K頁大小的表空間。數據頁大小在表空間創建時指定,不可更改。所以你需要做的是建一個更大數據頁大小的表空間,然後把表建到這個表空間, 命令如下:
1. create tablespace ts32k pagesize 32k managed by database using (FILE 'D:\ts32k\cont1' 2000)
2. create table ..... in ts32k
解決中文存儲進資料庫超過欄位最大容量的問題

閱讀全文

與db2命令建表相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:962
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:144
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:736
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:484
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:381
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:892
app轉賬是什麼 瀏覽:163