DB2常用語法(持續更新)

2021-10-23 05:33:01 字數 3193 閱讀 4139

由於常去生產排查問題,又沒有安裝視覺化工具,基本全靠命令,總結一下,不定時更新~

一、聯接資料庫

db2 connect to ***dbs

db2 connect to ***dbs user username using pass@word

列出所有使用者表

db2 list tables

二、解除安裝資料(備份資料):

1、 解除安裝乙個表中全部資料

db2 「export to 20200411.txt of del select * from table」

db2 「export to 20200411.txt of del modified by coldel | select * from table」

2、帶條件解除安裝乙個表中資料

db2 「export to 20200411.txt of del select * from table where id =『907020000』」

db2 「export to 20200411.txt of del select * from table where status=『01』」

db2 「export to 20200411.txt of del modified by coldel | select * from table where type =『01』」

三、載入資料:(匯入資料,回退指令碼常用)

1、 以預設分隔符載入,預設為「,」號

db2 「import from 20200411.txt of del insert into table」

2、 以指定分隔符「|」載入

db2 「import from 20200411.txt of del modified by coldel| insert into table」

四、刪除表中資料:

1、delete語句

db2 「delete from table」

db2 「delete from table where id=『907020000』 or id=『907010000』」

2、truncate (速度快,不可回滾)

db2 「truncate table 表名 immediate」

五、查詢資料結構及資料:

db2 「select * from table」

db2 「select * from table where id=『907020000』 and type=『0001』」

db2 「select id,name,type,number from table」

六、修改表中資料:

db2 「update table set type=0 where id=『907010000』 and status=『02』」

db2 「update table set type=0 where id=『02』 or id=『03』」

七、清除資料庫聯接

1、db2 backup db ***dbs

2、db2 move ***dbs export

db2 look -d ***dbs -e -x [-a] -o crttbl.sql

九、恢復資料庫

1、 db2 restore db ***dbs without rolling forward

2、 db2 -tvf crtdb.sql

crtdb.sql檔案內容:create db ***dbs on /db2catalog

db2 -stvf crttbl.sql

db2 move ***dbs import

十、檢視資料庫引數:

db2 get dbm cfg

db2 get db cfg for ***dbs

三、修改資料庫引數:

db2 update db cfg for ***dbs using logbufsz 20

db2 update db cfg for ***dbs using logfilsiz 5120

改完後,應執行以下命令使其生效:

db2 stop

db2 start

補充:

1、更改表字段長度

alter table 表名 alter 欄位名 set data type varchar(100)

2、新增表字段 設定預設值

alter table 表名 add column 欄位名 char(1) default 『0』

comment on column 表名.欄位名 is 『新增表字段的描述』

3、檢視當前資料庫表空間分配狀況

db2 list tablespaces show detail

4、重構表

①reorg table 表名

②call sysproc.admin_cmd(『reorg table 表名』)

5、檢視表結構

db2 describe table

6、列出所有資料庫

db2 list db directory

7、列出所有活動的資料庫

db2 list active databases

8、列出當前資料庫下所有的表

db2 list tables for all

db2 list tables for all | grep abd_ (搜尋abc開頭的表)

9、檢視版本

# db2level

10、顯示當前資料庫管理例項

$ db2 get instance

11、設定例項系統啟動時是否自動啟動。

$ db2iauto -on 自動啟動

$ db2iauto -off 不自動啟動

DB2常用語句

1.多表關聯批量更新 update tbl2 t2 set t2.b select t1.b from tbl1 t1 where t1.a t2.a fetch first 1 rows only 2.分頁查詢 select emp id,emp name from select rownumbe...

jQuery 常用語法總結 持續更新ing

color red blog遷移至 color url color blue size large jquery物件本身是乙個集合。size color color red size medium 說明 size color list 注意dom物件和jquery物件是有區別的,呼叫方法時要注意操作...

hana修改字段 HANA常用語法(持續更新)

hana常用語法梳理 1.schema 2.table 2.1 建立表 2.2 修改表 2.2.1 修改表名 2.2.2 修改表型別 2.2.3 修改表約束 2.2.4 修改字段 2.2.5 修改表分割槽 3.indexes 4.常用sql語句 1.schema 建立schema 語法 create...