DB2數據庫的應用是很普遍的,對於一些初學者來說,這些命令大全是首先要掌握的,接下來我就廢話不多說啦,直接為大家呈上DB2常用命令大全。
一、常用命令
1. 建立數據庫DB2_GCB
CREATE DATABASE DB2_GCB ON G: ALIAS DB2_GCB
USING CODESET GBK TERRITORY CN COLLATE USING SYSTEM DFT_EXTENT_SZ 32
2. 連接數據庫
connect to sample1 user db2admin using 8301206
3. 建立別名
create alias db2admin.tables for sysstat.tables;
CREATE ALIAS DB2ADMIN.VIEWS FOR SYSCAT.VIEWS
create alias db2admin.columns for syscat.columns;
create alias guest.columns for syscat.columns;
4. 建立表
create table zjt_tables as
(select * from tables) definition only;
create table zjt_views as
(select * from views) definition only;
5. 插入記錄
insert into zjt_tables select * from tables;
insert into zjt_views select * from views;
6. 建立視圖
create view V_zjt_tables as select tabschema,tabname from zjt_tables;
7. 建立觸發器
CREATE TRIGGER zjt_tables_del
AFTER DELETE ON zjt_tables
REFERENCING OLD AS O
FOR EACH ROW MODE DB2SQL
Insert into zjt_tables1 values(substr(o.tabschema,1,8),substr(o.tabname,1,10))
8. 建立唯一性索引
CREATE UNIQUE INDEX I_ztables_tabname
ON zjt_tables(tabname);
9. 查看表
select tabname from tables
where tabname='ZJT_TABLES';
10. 查看列
select SUBSTR(COLNAME,1,20) as 列名,TYPENAME as 類型,LENGTH as 長度
from columns
where tabname='ZJT_TABLES';
11. 查看表結構
db2 describe table user1.department
db2 describe select * from user.tables