`
Hero_dong
  • 浏览: 858 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
社区版块
存档分类
最新评论

db2常用命令

 
阅读更多

接触db2 也有好几个月了,是时候好好整理一下基础知识了!

一:连接、断开

1、数据库连接:

(缺省用户名和密码)db2 connect to  db_name ;

(完整命令) db2 connect  to db_name  user  user_name  using user_password;

 

2、查看数据库连接:

db2 list  application(s) ;

db2 list applications show detail;

 

3、断开数据连接:

db2 terminate;  (断开当前连接)

db2 force application ('8822','3243'); (断开指定的连接)

db2 force applications all;(断开所有连接)

二:增删改

1、常用的增、删、改、查:

select * from schema.tb_name;

update tb_name set col_name = ** ,col_name2 =**  where col_ =*;

delete from tb_name;

 

2、对数据库结构修改:

alter table  tb_name  add column    col_name  varchar(20);(增加列例子)

alter table tb_name  add column  col_name varchar(20)  add column col_name2 varcahr(30); (增加多列)

alter table tb_name  alter column  col_name  set  data  type  varchar(40); (只能增加字段长度,不能缩小)

alter table tb_name  drop column col_name ;(删除字段)

 

drop table  schema.tb_name;(删除表)

drop  database db_name;(删除数据库)

 

三:索引、存储过程

1、索引:

create index  index_name on schema.tb_name (

col_name   asc;

);(创建普通索引)

create unique index index_name on schema.tb_name(

col_name asc;

)ALLOW REVERSE SCANS; (唯一索引,并且允许反向扫描)

 

drop index index_name ;

 

(

reorg table schema.tb_name;

runstats on table schema.tb_naem  and index all ;

)

 

2.存储过程

 

create procedure  pro_name ( in |out|inout parameter_name data_type,.....)

  接着是主体部分;

 

call  pro_name(para1,para2,...);

call  pro_name(para1,para2,?);(带输出参数)

 

drop procedure pro_name;

 

重新绑定包:

 

SELECT   bname,pkgname, BSCHEMA  FROM     syscat.packagedep;

 

rebind package  schema.pro_pkgname;

 

 

(存储过程部分需要深入研究)

 

(待续)

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics