DB2数据库的应用是很普遍的,对于一些初学者来说,这些命令大全是首先要掌握的,接下来我就废话不多说啦,直接为大家呈上DB2常用命令大全。
CREATE DATABASE DB2_GCB ON G: ALIAS DB2_GCB
USING CODESET GBK TERRITORY CN COLLATE USING SYSTEM DFT_EXTENT_SZ 32
connect to sample1 user db2admin using 8301206
[@more@]
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;
create table zjt_tables as
(select * from tables) definition only;
create table zjt_views as
(select * from views) definition only;
insert into zjt_tables select * from tables;
insert into zjt_views select * from views;
create view V_zjt_tables as select tabschema,tabname from zjt_tables;
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))
CREATE UNIQUE INDEX I_ztables_tabname
ON zjt_tables(tabname);
select tabname from tables
where tabname='ZJT_TABLES';
select SUBSTR(COLNAME,1,20) as 列名,TYPENAME as 类型,LENGTH as 长度
from columns
where tabname='ZJT_TABLES';
db2 describe table user1.department
db2 describe select * from user.tables
db2 describe indexes for table user1.department
select viewname from views
where viewname='V_ZJT_TABLES';
select indname from indexes
where indname='I_ZTABLES_TABNAME';
SELECT SUBSTR(PROCSCHEMA,1,15),SUBSTR(PROCNAME,1,15)
FROM SYSCAT.PROCEDURES;
ip datatype:varchar
select cast(ip as integer)+50 from log_comm_failed
connect reset
disconnect db2_gcb
LIST APPLICATION;
FORCE APPLICATION(0);
db2 force applications all (强迫所有应用程序从数据库断开)
lock table test in exclusive mode
lock table test in share mode
list tables
list tables for system
list active databases
list command options
LIST DATABASE DIRECTORY
list tablespaces
LIST TABLESPACE CONTAINERS FOR
Example: LIST TABLESPACE CONTAINERS FOR 1
GET AUTHORIZATIONS
DB2START
db2stop
grant select,delete,insert,update on tables to user
grant all on tables to user WITH GRANT OPTION
GRANT EXECUTE
ON PACKAGE PACKAGE-name
TO PUBLIC
GRANT CREATEIN ON SCHEMA SCHEMA-name TO USER
grant connect,createtab,dbadm on database to user
grant control on index index-name to user
例:? SQL30081
help statement
例如,help SELECT
sqlstate 或 ? class-code
db2admin setid username password
db2sampl
db2sampl F:(指定安装盘)
! dir
SELECT EMPNO, CAST(RESUME AS VARCHAR(370))
FROM EMP_RESUME
WHERE RESUME_FORMAT = 'ascii'
要运行 DB2 Java 存储过程或 UDF,还需要更新服务器上的
DB2 数据库管理程序配置,以包括在该机器上安装 JDK 的路径
db2 update dbm cfg using JDK11_PATH d:sqllibjavajdk
TERMINATE
update dbm cfg using SPM_NAME sample
db2 get dbm cfg