導航:首頁 > 程序命令 > db2查詢命令行

db2查詢命令行

發布時間:2023-05-28 15:24:10

① 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)

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

db2 cmd命令操作

1、 打開命令行窗口
#db2cmd
2、 打開控制中心 www.2cto.com
# db2cmd db2cc
3、 打開命令編輯器
db2cmd db2ce
=====操作資料庫命令=====
4、 啟動資料庫實例
#db2start
5、 停止資料庫實例
#db2stop
如果你不能停止資料庫由於激活的連接,在運行db2stop前執行db2 force application all就可以了 /db2stop force
6、 創建資料庫
#db2 create db [dbname]
7、 連接到資料庫 www.2cto.com
#db2 connect to [dbname] user [username] using [password]
8、 斷開資料庫連接
#db2 connect reset
9、 列出所有資料庫
#db2 list db directory
10、 列出所有激活的資料庫
#db2 list active databases
11、 列出所有資料庫配置
#db2 get db cfg
12、 刪除資料庫
#db2 drop database [dbname]
(執行此操作要小心)
如果不能刪除,斷開所有資料庫連接或者重啟db2
=========操作數據表命令==========
13、 列出所有用戶表
#db2 list tables
14、列出所有系統表
#db2 list tables for system
15、列出所有表
#db2 list tables for all
16、 列出系統表
#db2 list tables for system
17、列出用戶表
#db2 list tables for user
18、 列出特定用戶表
#db2 list tables for schema [user]
19、 創建一個與資料庫中某個表(t2)結構相同的新表(t1)
#db2 create table t1 like t2
20、 將一個表t1的數據導入到另一個表t2
#db2 "insert into t1 select * from t2"
21、 查詢表
#db2 "select * from table name where ..."
22、 顯示表結構
#db2 describe table tablename
23、 修改列
#db2 alter table [tablename] alter column [columname] set data type varchar(24)
======腳本文件操作命令=======
24、 執行腳本文件
#db2 -tvf scripts.sql
25、幫助命令
* 查看命令幫助
#db2 ? db2start
* 查看錯誤碼信息
#db2 ? 22001
* memo: 詳細命令請使用"db2 ? <command>"進行查看。
=========================
26、備份資料庫
#db2 backup db <db name>
備註:執行以上命令之前需要斷開資料庫連接
27、在線備份資料庫
#db2 -v "BACKUP DATABASE <database name> ONLINE TO <path> WITH 2 BUFFERS BUFFER 1024 INCLUDE LOGS WITHOUT PROMPTING"
28、恢復資料庫
#db2 restore db <source db name>
29、在線恢復資料庫
#db2 "RESTORE DB <database name> TO <db path> LOGTARGET <logpath> WITHOUT PROMPTING"
#db2 "ROLLFORWARD DB <database name> TO END OF LOGS AND STOP" ...
30、導出數據文件
#db2move <db name> export
[-sn <模式名稱,一般為db2admin>]
[-tn <表名,多個之間用逗號分隔>]
31、導入數據文件
#db2move <db name> import
32、獲取db2資料庫管理配置環境信息
#db2 get dbm cfg
33、.獲取db2某個資料庫資料庫管理配置環境信息
#db2 get db cfg for <db name>
或者:連接至某個資料庫以後執行db2 get db cfg
34、更改db2日誌空間的大小
備註:以下命令為了防止db2資料庫過份使用硬碟空間而設,僅用於開發者自己機器上的db2,如果是伺服器,則參數需要修改。
#db2 UPDATE DB CFG FOR <db name> USING logretain OFF logprimary 3 logsecond 2 logfilsiz 25600;
如果頁大小是4KB,則以上命令創建3個100M的日誌文件,佔用300MB硬碟空間。25600*4KB=102400KB。
35、創建臨時表空間
#DB2 CREATE USER TEMPORARY TABLESPACE STMASPACE PAGESIZE 32 K MANAGED BY DATABASE USING (FILE 'D:\DB2_TAB\STMASPACE.F1' 10000)
EXTENTSIZE 256
36、獲取資料庫管理器的快照數據
#db2 –v get snapshot for dbm
37、顯示進行程號
#db2 list applications show detail
===================================================
一、載入數據:
1、 以默認分隔符載入,默認為「,」號
db2 "import from btpoper.txt of del insert into btpoper"
2、 以指定分隔符「|」載入
db2 "import from btpoper.txt of del modified by coldel| insert into btpoper"
二、卸載數據:
1、 卸載一個表中全部數據
db2 "export to btpoper.txt of del select * from btpoper"
db2 "export to btpoper.txt of del modified by coldel| select * from btpoper"
2、 帶條件卸載一個表中數據
db2 "export to btpoper.txt of del select * from btpoper where brhid='907020000'"
db2 "export to cmmcode.txt of del select * from cmmcode where codtp='01'"
db2 "export to cmmcode.txt of del modified by coldel| select * from cmmcode where codtp='01'"
三、查詢數據結構及數據:
db2 "select * from btpoper"
db2 "select * from btpoper where brhid='907020000' and oprid='0001'"
db2 "select oprid,oprnm,brhid,passwd from btpoper"
四、刪除表中數據:
db2 "delete from btpoper"
db2 "delete from btpoper where brhid='907020000' or brhid='907010000'"
五、修改表中數據:
db2 "update svmmst set prtlines=0 where brhid='907010000' and jobtp='02'"
db2 "update svmmst set prtlines=0 where jobtp='02' or jobtp='03'"
六、聯接資料庫
db2 connect to btpdbs
七、清除資料庫聯接
db2 connect reset 斷開資料庫連接
db2 terminate 斷開資料庫連接
db2 force applications all 斷開所有資料庫連接
八、備份資料庫
1、 db2 backup db btpdbs
2、 db2move btpdbs export
db2look -d btpdbs -e -x [-a] -o crttbl.sql
九、恢復資料庫
1、 db2 restore db btpdbs without rolling forward
2、 db2 -tvf crtdb.sql
crtdb.sql文件內容:create db btpdbs on /db2catalog
db2 -stvf crttbl.sql
db2move btpdbs import
十、DB2幫助命令:
db2 ?
db2 ? restroe
db2 ? sqlcode (例:db2 ? sql0803) 註:code必須為4位數,不夠4位,前面補0

③ 怎樣使用命令行執行DB2的SQL

一、准備工作
運行db2cmd或者db2cw打開DB2命令行處理器

進入SQL腳本存放目錄

用db2 connect to <dbname> user <username> using <password> 命令連接資料庫

用db2 set current schema <schema_name> 設置當前的SCHEMA,這個SCHEMA可以是未創建的,DB2會自動創建。
二、執行不同類型的SQL

1、在命令行執行簡單SQL命令

db2 <SQL語句內容>

2、在命令行執行SQL腳本文件

db2 -td; -cf <SQL腳本文件路徑> -l <輸出日誌文件路徑>

說明:-td; 指定語句結束標志。因為一般SQL都是以分號結尾,所以就寫成「-td;」。

-l <輸出日誌文件路徑> 是可選的。

3、在命令行執行DB2 存儲過程文件
db2 -td@ -f <SQL過程文件路徑> -l <輸出日誌文件路徑>

說明:-td@ 指定語句結束標志。因為一般SQL過程都是以@結尾,所以就寫成「-td@」。

-l <輸出日誌文件路徑> 是可選的。

④ db2資料庫命令

1、db2 connect to <資料庫名> --連接到本地資料庫名

db2 connect to <資料庫名> user <用戶名> using <密碼> --連接到遠端資料庫

2、 db2 force application all --強迫所有應用斷開資料庫連接(非同步的)

3、db2 backup db db2name<資料庫名稱> --備份整個資料庫數據

db2 restore db <db2name> --還原資料庫

db2 restore database far_test from /home/db2inst1 taken at 20150304215844

4、db2 list application --查看所有連接(需要連接到具體資料庫才能查看)

5、db2start --啟動資料庫

db2stop --停止資料庫

db2stop force--停止資料庫

6、create database <資料庫名> using codeset utf-8 territory CN --創建資料庫使用utf-8編碼

⑤ db2常用命令

操作資料庫命令

1、 啟動資料庫實例

#db2start

2、 停止資料庫實例

#db2stop

如果你不能停止資料庫由於激活的連接,在運行db2stop前執行db2 force application all就可以了 /db2stop force

3、 創建資料庫

#db2 create db [dbname]

4、 連接到資料庫

#db2 connect to [dbname] user[username] using [password]

5、 斷開資料庫連接

#db2 connect reset

操作數據表命令

1、 列出所有用戶表

#db2 list tables

2、列出所有系統表

#db2 list tables for system

3、列出所有表

#db2 list tables for all

4、 列出系統表

#db2 list tables for system

5、列出用戶表

#db2 list tables for user

6、 列出特定用戶表

#db2 list tables for schema[user]

⑥ 在DB2資料庫中 有什麼命令可以查看當前有哪些資料庫

你好4. 查看系岩爛統資料庫目錄 db2 list database directory 5. 查看本地資料庫目錄 db2 list database directory on <盤符> 在本地數粗局漏據庫目錄中有而系統資料庫目錄中沒有的資料庫不能訪問,可以在控制中心中選中<資料庫>右鍵單擊選擇添加,然後輸入需要添加的資料庫名臘前稱或者點擊刷新按鈕選擇資料庫,加入資料庫後即可以訪問。

⑦ 在DB2命令行中什麼命令能查看資料庫所在實例

db2ilist可以查看系統上的所有實例,有一個環境變數可以設置默認啟動的實例。如果是在Lniux或UNIX系統,會存在一個實例用戶,用這個實例用戶連接的實例名與實例用戶名相同。

副本跟實例不是一個概念。一個副本可以理解為一個DB2資料庫產品的安裝,一個系統上可以安裝多個副本,主要是為了在同一個系統上使用多個DB2的版本,比如V8 和 V9。安裝DB2時如果系統里不存在一個叫DB2的實例,則會默認創建名為DB2的實例,如果已經存在,則會創建DB2_01,依此類推

閱讀全文

與db2查詢命令行相關的資料

熱點內容
羅曼史生孩子在那一段在幾分鍾 瀏覽:951
成龍40部經典電影 瀏覽:794
程序員連出兩次線上事故 瀏覽:426
啄木鳥電影什麼意思 瀏覽:292
主角叫柱子的鄉村小說 瀏覽:962
肉特別多的電影 瀏覽:970
好的在觀看網站 瀏覽:307
vip免費影視劇網站 瀏覽:924
恐怖鬼片免費版在線觀看 瀏覽:539
印度神話電影排行前十 瀏覽:510
主角開飛機重生流 瀏覽:760
java函數式編程教程 瀏覽:271
天正圖紙加密後的效果 瀏覽:909
泰安汽車解壓郵政網點 瀏覽:410
泰國鬼片在線觀看免費收看 瀏覽:695
彼時曾相伴免費觀看完整版 瀏覽:254
網站在線觀看什 瀏覽:159
食嬰鬼整部電影 瀏覽:360
印度電影愛經 瀏覽:642
搜播比神馬更好看的影視 瀏覽:82