IBM DB2上機操作指南
1.啟動實例(db2inst1):實例相當于informix中的服務
db2start
2.停止實例(db2inst1):
db2stop
3.列出所有實例(db2inst1)
db2ilist
4.列出當前實例:
db2 get instance
5.察看示例配置文件:
db2 get dbm cfg|more
6.更新數據庫管理器參數信息:
db2 update dbm cfg using para_name para_value
7.創建數據庫:
db2 create db test
8.察看數據庫配置參數信息
db2 get db cfg for test|more
9.更新數據庫參數配置信息
db2 update db cfg for test using para_name para_value
10.刪除數據庫:
db2 drop db test
11.連接數據庫
db2 connect to test
12.列出所有表空間的詳細信息。
db2 list tablespaces show detail
13.列出容器的信息
db2 list tablespace containers for tbs_id show detail
13.創建表:
db2 ceate table tb1(id integer not null,name char(10))
14.列出所有表
db2 list tables
15.插入數據:
db2 insert into tb1 values(1,’sam’);
db2 insert into tb2 values(2,’smitty’);
16.查詢數據:
db2 “select * from tb1”
17.刪除數據:
db2 delete from tb1 where id=1
18.創建索引:
db2 create index idx1 on tb1(id);
19.創建視圖:
db2 create view view1 as select id from tb1
20.查詢視圖:
db2 select * from view1
21.節點編目
db2 catalog tcp node node_name remote server_ip server server_port
22.察看端口號
db2 get dbm cfg|grep SVCENAME
23.節點的附接
db2 attach to node_name
24.察看本地節點
db2 list node direcotry
25.節點反編目
db2 uncatalog node node_name
26.數據庫編目
db2 catalog db db_name as db_alias at node node_name
27.察看數據庫的編目
db2 list db directory
28.連接數據庫
db2 connect to db_alias user user_name using user_password
29.數據庫反編目
db2 uncatalog db db_alias
30.導出數據
db2 export to myfile of ixf messages msg select * from tb1
31.導入數據
db2 import from myfile of ixf messages msg replace into tb1
32.導出數據庫的所有表數據
db2move test export
33.生成數據庫的定義
db2look -d db_alias -a -e -m -l -x -f -o db2look.sql
34.創建數據庫
db2 create db test1
35.生成定義
db2 -tvf db2look.sql
36.導入數據庫所有的數據
db2move db_alias import
37.重組檢查
db2 reorgchk
38.重組表tb1
db2 reorg table tb1
39.更新統計信息
db2 runstats on table tb1
40.備份數據庫test
db2 backup db test
41.恢復數據庫test
db2 restore db test
42. 擁有實例的所有程序列表
db2 list application
43.
db2 terminate
44.查看數據表結構
db2 “describe select * from ggwdxtcs”
/*啟動命令界面 */ db2cmd
/*查看幫助*/ db2 ? *
/*連接數據庫*/ db2 connect to user using
/*查看數據庫實例*/ db2ilist
/*啟動數據庫*/ db2start
/*停止數據庫應用*/ db2 force applications all
/*停數據庫*/ db2stop
/*查看表空間* db2 list tablespaces show detail
/*查看表是否有記錄*/ db2 select count(*) from
/*從文本導入到數據庫表中*/ db2 import from ***.ixf of ixf modified by forcein commitcount 1000 insert into
modified by forcein /*數據庫數據在AIX 和 windows 不同版本之間的格式轉換*/
commitcount **** /*防止數據庫提交過多,引起交易日志滿,1000-5000 為宜*/
例子:db2 "import from c:\zj\321104\bbsybsj.ixf of ixf modified by forcein insert into bbsybsj"
/*查看sql語句錯誤解釋*/ db2 ? sql**** ****為四位出錯編碼,不足位前補0
db2 ? “sqlstate”
db2 ? sqlstate=42884
db2 “select * from syscat.functions” |grep –i rtrim
db2 “select * from syscat.indexes”
表增加列
db2 alter table 表名 add column 字段名 varchar(4)(字段類型)
修改表里的字段
db2 update 表名 set 字段名='xxx' where .....