===========================================================
DB2常用命令大全
===========================================================
作者: paodekuai(http://paodekuai.itpub.net)
发表于: 2006.08.23 10:46
分类:
DB2
出处: http://paodekuai.itpub.net/post/1196/197463
---------------------------------------------------------------
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
12. 查看表的索引
db2 describe indexes for table user1.department
13. 查看视图
select viewname from views
where viewname='V_ZJT_TABLES';
14. 查看索引
select indname from indexes
where indname='I_ZTABLES_TABNAME';
15. 查看存贮过程
SELECT SUBSTR(PROCSCHEMA,1,15),SUBSTR(PROCNAME,1,15)
FROM SYSCAT.PROCEDURES;
16. 类型转换(cast)
ip datatype:varchar
select cast(ip as integer)+50 from log_comm_failed
17. 重新连接
connect reset
18. 中断数据库连接
disconnect db2_gcb
19. view application
LIST APPLICATION;
20. kill application
FORCE APPLICATION(0);
db2 force applications all (强迫所有应用程序从数据库断开)
21. lock table
lock table test in exclusive mode
22. 共享
lock table test in share mode
23. 显示当前用户所有表
list tables
24. 列出所有的系统表
list tables for system
25. 显示当前活动数据库
list active databases
26. 查看命令选项
list command options
27. 系统数据库目录
LIST DATABASE DIRECTORY
28. 表空间
list tablespaces
29. 表空间容器
LIST TABLESPACE CONTAINERS
一、常用命令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
12. 查看表的索引
db2 describe indexes for table user1.department
13. 查看视图
select viewname from views
where viewname='V_ZJT_TABLES';
14. 查看索引
select indname from indexes
where indname='I_ZTABLES_TABNAME';
15. 查看存贮过程
SELECT SUBSTR(PROCSCHEMA,1,15),SUBSTR(PROCNAME,1,15)
FROM SYSCAT.PROCEDURES;
16. 类型转换(cast)
ip datatype:varchar
select cast(ip as integer)+50 from log_comm_failed
17. 重新连接
connect reset
18. 中断数据库连接
disconnect db2_gcb
19. view application
LIST APPLICATION;
20. kill application
FORCE APPLICATION(0);
db2 force applications all (强迫所有应用程序从数据库断开)
21. lock table
lock table test in exclusive mode
22. 共享
lock table test in share mode
23. 显示当前用户所有表
list tables
24. 列出所有的系统表
list tables for system
25. 显示当前活动数据库
list active databases
26. 查看命令选项
list command options
27. 系统数据库目录
LIST DATABASE DIRECTORY
28. 表空间
list tablespaces
29. 表空间容器
LIST TABLESPACE CONTAINERS FOR
Example: LIST TABLESPACE CONTAINERS FOR 1
30. 显示用户数据库的存取权限
GET AUTHORIZATIONS
31. 启动实例
DB2START
32. 停止实例
db2stop
33. 表或视图特权
grant select,delete,insert,update on tables to user
grant all on tables to user WITH GRANT OPTION
34. 程序包特权
GRANT EXECUTE
ON PACKAGE PACKAGE-name
TO PUBLIC
35. 模式特权
GRANT CREATEIN ON SCHEMA SCHEMA-name TO USER
36. 数据库特权
grant connect,createtab,dbadm on database to user
37. 索引特权
grant control on index index-name to user
38. 信息帮助 (? XXXnnnnn )
例:? SQL30081
39. SQL 帮助(说明 SQL 语句的语法)
help statement
例如,help SELECT
40. SQLSTATE 帮助(说明 SQL 的状态和类别代码)
? sqlstate 或 ? class-code
41. 更改与"管理服务器"相关的口令
db2admin setid username password
42. 创建 SAMPLE 数据库
db2sampl
db2sampl F:(指定安装盘)
43. 使用操作系统命令
! dir
44. 转换数据类型 (cast)
SELECT EMPNO, CAST(RESUME AS VARCHAR(370))
FROM EMP_RESUME
WHERE RESUME_FORMAT = 'ascii'
45. UDF
要运行 DB2 Java 存储过程或 UDF,还需要更新服务器上的
DB2 数据库管理程序配置,以包括在该机器上安装 JDK 的路径
db2 update dbm cfg using JDK11_PATH d:sqllibjavajdk
TERMINATE
update dbm cfg using SPM_NAME sample
46. 检查 DB2 数据库管理程序配置
db2 get dbm cfg
47. 检索具有特权的所有授权名
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'DATABASE' FROM SYSCAT.DBAUTH
UNION
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'TABLE ' FROM SYSCAT.TABAUTH
UNION
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'PACKAGE ' FROM SYSCAT.PACKAGEAUTH
UNION
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'INDEX ' FROM SYSCAT.INDEXAUTH
UNION
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'COLUMN ' FROM SYSCAT.COLAUTH
UNION
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'SCHEMA ' FROM SYSCAT.SCHEMAAUTH
UNION
SELECT DISTINCT GRANTEE, GRANTEETYPE, 'SERVER ' FROM SYSCAT.PASSTHRUAUTH
ORDER BY GRANTEE, GRANTEETYPE, 3
create table yhdab
(id varchar(10),
password varchar(10),
ywlx varchar(10),
kh varchar(10));
create table ywlbb
(ywlbbh varchar(8),
ywmc varchar(60))
48. 修改表结构
alter table yhdab ALTER kh SET DATA TYPE varchar(13);
alter table yhdab ALTER ID SET DATA TYPE varchar(13);
alter table lst_bsi alter bsi_money set data type int;
insert into yhdab values
('20000300001','123456','user01','20000300001'),
('20000300002','123456','user02','20000300002');
49. 业务类型说明
insert into ywlbb values
('user01','业务申请'),
('user02','业务撤消'),
('user03','费用查询'),
('user04','费用自缴'),
('user05','费用预存'),
('user06','密码修改'),
('user07','发票打印'),
('gl01','改用户基本信息'),
('gl02','更改支付信息'),
('gl03','日统计功能'),
('gl04','冲帐功能'),
('gl05','对帐功能'),
('gl06','计费功能'),
('gl07','综合统计')
二. 目录视图说明
说明 目录视图
检查约束 SYSCAT.CHECKS
列 SYSCAT.COLUMNS
检查约束引用的列 SYSCAT.COLCHECKS
关键字中使用的列 SYSCAT.KEYCOLUSE
数据类型 SYSCAT.DATATYPES
函数参数或函数结果 SYSCAT.FUNCPARMS
参考约束 SYSCAT.REFERENCES
模式 SYSCAT.SCHEMATA
表约束 SYSCAT.TABCONST
表 SYSCAT.TABLES
触发器 SYSCAT.TRIGGERS
用户定义函数 SYSCAT.FUNCTIONS
视图 SYSCAT.VIEWS
三. 字符串类型
二进制大对象 (BLOB) 字符串。
字符大对象 (CLOB) 字符串,它的字符序列可以是单字节字符或多字节字符,
或这两者的组合。
双字节字符大对象 (DBCLOB) 字符串,它的字符序列是双字节字符。
四. 数据库范式
第一种规范形式:表中的每一行和每一列均有一个值,永远不会是一组值。
第二种规范形式:不在关键字中的每一列提供取决于整个关键字的事实。
第三种规范形式:每个非关键字列提供与其他非关键字列无关并只取决于该关键字的事实。
第四种规范形式:没有行包含有关一个实体的两个或更多个独立的多值事实。
五. 数据类型
数据类型 类型 特性 示例或范围
CHAR(15) 定长字符串 最大长度为 254 'Sunny day '
VARCHAR(15) 变长字符 最大长度为 4000 'Sunny day'
SMALLINT 数字 长度为 2 字节精度为 5 位范围为-32768 至 32767
INTEGER 数字 长度为 4 字节精度为 10 位范围为-2147483648 至 2147483647
REAL 数字 单精度浮点32 位近似值 范围为-3.402E+38至-1.175E-37或
1.175E-37 至-3.402E+38或零
DOUBLE 数字 双精度浮点64 位近似值 范围为-1.79769E+308
至-2.225E-307或 2.225E-307 至 1.79769E+308或零
DECIMAL(5,2) 数字 精度为 5小数位为 2 范围为 -10**31+1 至 10**31-1
DATE 日期时间 三部分值 1991-10-27
TIME 日期时间 三部分值 13.30.05
TIMESTAMP 日期时间 七部分值 1991-10-27-13.30.05.000000
六. 列函数
列函数对列中的一组值进行运算以得到单个结果值。下列就是一些列函数的示例。
AVG
返回某一组中的值除以该组中值的个数的和
COUNT
返回一组行或值中行或值的个数
MAX
返回一组值中的最大值
MIN
返回一组值中的最小值
七. 标量函数
标量函数对值进行某个运算以返回另一个值。
下列就是一些由DB2 通用数据库提供的标量函数的示例。
ABS
返回数的绝对值
HEX
返回值的十六进制表示
LENGTH
返回自变量中的字节数(对于图形字符串则返回双字节字符数。)
YEAR
抽取日期时间值的年份部分
paodekuai
发表于:2006.08.23 10:46
::分类:
(
DB2
)
::阅读:(214064次)
::
评论
(18)

re: DB2常用命令大全
[回复]
客气客气,最近太忙了,都没有更新
paodekuai
评论于: 2007.08.23 21:25

我想下载就抱歉 X Rumer 7.0.10 ??
[回复]
如何释放 XRumer 7.0.10 ??
给我网址!
NatashaLed
评论于: 2012.01.22 15:11

MY WIFE IS A CHEATING -------- SEE FOR YOURSELF!
[回复]
I have just found out that my wife has been cheating on me for at least 16 months. She suspects that i know something, but I have not confronted her yet. The reasons i am hesitant to confront her vary from financial to depending how angry and depressed i am, plotting my revenge. The question I have and why i am turning to you is that I am not really in any condition to be making life decisions right now. I would like some level headed advice as to what to do.
My wife has a second cell phone in which it is plainly obvious that the person she is texting, she is Being Intimate with. She comes home after work, I work 2nd shift at a local prison,, she meets him at our house. I know this because i put in hidden cameras. I have been saving this footage for over a year.
I know that most of these posts are about should i forgive my wife for cheating. I say do so at your own peril. I say forgiving your wife is the risky decision. I say this because I have forgiven my wife the last time she cheated on me and that decision has landed me here, again. Last time my daughter was 12 years old when it happened and now she almost 17. Her well being was part of my decision to forgive my wife the first time, however I beleive that she is old enough now to handle Mom and Dad divorcing. At least understand it better. I have uploaded the vedios to a couple sites please check them out and tell me if i should leave them for her to find maybe spread them FURTHER
here are the sites
ereceduep
评论于: 2012.02.07 09:54

Best Nutritional vitamins for Major depression
[回复]
Are you currently among the lots of people struggling with depressive disorders however looking for natural options to prescribed drugs? In that case, you might be buy adderall online wondering which are the best nutritional vitamins for depression.
plobedepe
评论于: 2012.02.10 18:19
[回复]
zvmslpqtyu
评论于: 2012.03.13 00:35

You are what you eat , Acai Berry is the worlds # 1 super foOD.
[回复]
Most people who suffer from obesity have the problem of bulging waistline. They suffer a lot mentally and physically for being over weight and most of them are in search of some remedy that could help them to reduce their waistline. Then it is high time that you have to look for options where you could lessen the body weight as well as cleanse the toxins in your body making it into a perfect body structure then turn your focus over to the highly effective product of Pure Acai Flush. This pure acai flush is a natural weight loss supplements which works effectively to lower all your excess body weight surrounding your body and provides you wonderful physique in a short period. The best thing about the pure acai is that it works best for all ages of men and women.
This acai berry pure acai flush works in a way where it get rid of excess flashy chunks of fat, that making you look so big and causing you to lose your confidence. All the ingredients that are involved with this acai berry have all powers to get rid of all the toxins and waste materials in your body and provides a healthy body constitution. However the anti oxidants that is involved inside the acai berry is certain to eliminate all the toxic and unwanted waste substances which are hiding behind the intestinal, bowels etc which can cause several disorders within your body. This pure acai flush is 100% natural and clinically tested to that they are 100% safe to use them.
Another major aspect that is featured with the pure acai flush is that it aids your digestive tract absorb and provides well balanced metabolic activity inside the body. This product helps in providing well toned body structure by helping to lose the excess pounds but also provides other major advantages to stay healthy for long. The advantages of them are listed below
foutraree
评论于: 2012.03.24 06:05

powermta nulled
[回复]
Hey
I have powermta nulled for sale.
Good price. I provide full support , installation and mailing servers if needed.
ICQ me on 25547820
em. triggermailing @ gmail.com.
Tooncodymmend
评论于: 2012.04.01 12:59

I found Best site! Wow
[回复]
Srakotronos
评论于: 2012.04.15 09:26

propecia success rates
[回复]
primidone 50 mg side effects - sinemet pharmacologybuy vermoxhow long does it take for misoprostol to workbactrim sinus infectionretin a micro 0.04 gel
Ciciossicleda
评论于: 2012.04.16 01:22

I found Best site! Errby
[回复]
Srakotraqu
评论于: 2012.04.18 09:46

Knowledge to blog
[回复]
Seedbox hosting is a lot of exciting. You can get a quickly seedbox when you get a very good provider. Go here for the best seedbox!
heibefrobre
评论于: 2012.04.22 07:13

蒡
[回复]
ReipssesBuh
评论于: 2012.04.28 23:31

Transmission Warehouse
[回复]
At Transmission Warehouse in Las Vegas, NV, our customers come first. We provide prompt, honest transmissions services at reasonable prices. Our staff is well-trained to get you and your loved ones safely back on the road. We are the best Transmission Shop in Las Vegas! Don't hesitate to call us today for any transmission service estimate. Visit http://www.vegas-transmissionrepair.com today.
Attactvor
评论于: 2012.04.29 01:49

nike denmark
[回复]
If you have decided to rather hammer off Oakleys glasses than costing along least a hundred dollars aboard authentic pairs, it namely important to reserve in mind some things apt aid you win quality knockoff pair mulberry outlet of eyewear instead of just obtaining cheaply looking fakes To retention more on your money, you can instead purchase several knockoff pairs rather than limiting your buy on a alone pair The practical behalf is that you can actually brag your knockoff sun glasses to your friends without them noticing its difference with aboriginal glasses.
A Beginner's Guide To Finding Knock Off Oakleys
Well,if you are an avid buyer of beat off Oakleys,afterward you might as well buy majorities of eyewear and avail the opportunity of selling those pairs. Not only can you give your friends and colleagues the Oakley experience merely also assistance them save aboard their money as well as providing protection as their eyes.
Once you are resolved surrounded buying your set of beat off Oakleys, do never forget that there is still that colossal distinction between the aboriginal pairs and the copy Authentic Oakley glasses definitely give the advantage of filtering out the sun's ultraviolet rays,while knockoff eyewear only cater defend from the stifling glare of the sun.
Of course,knowing a few tips meantime purchasing beat off Oakleys are a colossal aid apt getting the right quality you deserve as consumer. For one thing, you have to see as knockoff eyewear that are never especially sordid Mulberry handbags cheap As much as feasible gather forever your alternatives as knockoff sun glasses and cautiously mulberry outlet stores favor the pair that has the best quality between the rest In particular, keenly impede the smoothness and finish texture of the products. If you find that the surface namely rough do never buy that chip of knockoff. Also penetrate out as cracks or scratches on the product.
Whether you bought inferiorly made beat off Oakleys from online stores or picked a couple from avenue vendors, plastic Oakleys alternatively foakleys ambition still crack for of their inexpensive quality. However, you can obtain the advantage of purchasing these knockoff glasses only if you acquaint sure that the sunglasses you aspiration buy are never of extremely inexpensive quality. This ought give you more merit as those hard-earned dollars.
Just because the invaluable Oakleys priced you hundreds of dollars it does never mean they are made of reinforced titanium or something. Plastic aspiration give access whether it is accustom in dirt-cheap buffet off Oakleys alternatively otherwise. The aboriginal Oakley's individually from serving as a protection from the rough sun is likewise a alcove fashion statement that is meant to accentuate your class. But that namely the more conventional way out. There are still other ways to penetrate classy even with a couple of beat off Oakleys at the peak of you know which ones to buy.
billige nike sko,
http://www.mulberry-handbags-sale.co.uk/mulberryhandbags/ - sales|
http://www.mulberry-handbags-sale.co.uk/ - sale|
http://www.suprashoes-mall.com/suprashoes/ - blog|
http://www.suprashoes-mall.com/ - sale|
http://www.nikeairjordanshoessales.com/RetroJordan/ - blog|
http://www.nikeairjordanshoessales.com/ - blogs|
http://www.suprashoes-mall.com/ - sale|
http://www.outlettresorparis.com/ - sale|
http://www.justinbieber-suprashoes.com/ - cheap|
http://www.isabelmarantsneakersboots.com/isabelmarantsneakers/ - sales|
http://www.isabelmarantsneakersboots.com/ - blog|
http://www.outlettresorparis.com/bracelets/ - blogs|
http://www.outlettresorparis.com/ - cheap|
http://www.mulberry-uk-sale.com/ - sales|
http://www.mulberrysaleoutletuk.com/ - blogs|
http://www.mulberry-uk-sale.com/mulberryoutlet/ - cheap|
http://www.mulberrysaleoutletuk.com/mulberryoutletuk/ - blog|
http://ugg.sitemix.jp/ - cheap|
http://phpfox.sitemix.jp/blog/ - sales|
http://www.cheap-oakleysunglassesoutlet.org/ - sale|
http://www.cheap-oakleysunglassesoutlet.org/oakleysunglasses/ - sale|
http://www.justinbieber-suprashoes.com/suprashoes/ - blog
http://www.asicsrunningshoesaustralia.org/ - cheap
http://asicsrunningshoesaustralia.org/asicsaustralia/ - blogs
endonound
评论于: 2012.05.17 10:13