NOVOTS KMS 词汇表 Glossary    联系我们 Contact Us
查询 Search  
   
按类别浏览 Browse by Category
NOVOTS KMS .: 数据库 .: DB2 alter table 与 reorg tablename

DB2 alter table 与 reorg tablename

 对表进行任何操作都不被允许,提示SQLSTATE=57016 SQLCODE=-668 ,原因码 "7"的错误:SQL0668N Operation not allowed for reason code "7" on table XXX.SQLSTATE=57016
解决方法为:执行命令:reorg table XXX;即可。
参考原文为:
Operation not allowed for reason code reason-code on table table-name.
Explanation: Access to table table-name is restricted. The cause is based on the following reason codes reason-code: 7
The table is in the reorg pending state. This can occur after an ALTER TABLE statement containing a REORG-recommended operation.7
Reorganize the table using the REORG TABLE command (note that INPLACE REORG TABLE is not allowed for a table that is in the reorg pending state).

其中:
reorg table 通过重构行来消除“碎片”数据并压缩信息,对表进行重组。
runstats on table . 收集表 的统计信息。
reorgchk on table all 确定是否需要对表进行重组,对于对所有表自动执行 runstats 很有用。
>>> reorg 和runstats 都是单个表优化,初始化的命令:
runstats on table administrator.test;
reorg table administrator.test;


ALTER TABLE操作在日常开发中很常见,下面是摘自DB2官网关于ALTER TABLE操作的一段话。

Perhaps the most important thing to realize when running an ALTER TABLE statement containing a REORG-recommended operation is that once the ALTER TABLE statement has executed, the table will be placed in the Reorg Pending state. This means that the table is inaccessible for almost all operations until you perform a REORG. See the ALTER TABLE statement in the SQL Referencefor the complete list of ALTER TABLE operations, some of which are also called REORG-recommended operations.

简单地说就是运行ALTER TABLE时要注意当前运行的语句是否需要执行REORG操作,对于这样的ALTER TABLE语句,如果不执行REORG操作的话,基本上目标表就不再可用。至于什么样的语句需要REORG,什么样的不需要,看SQL Reference去!下面是一个具体的例子演示:
DB2 <wbr>ALTER <wbr>TABLE与REORG <wbr>TABLENAME

代码有四种颜色,绿色代表不需要执行REORG的语句,红色代表需要执行REORG的语句,黄色是REORG语句,白色你懂的。从代码上可以看出,红色高亮语句虽然要求使用REORG,但不及时运行REORG还可以让后续的几个语句继续执行。原因是DB2允许最多三条语句处于Reorg Pending状态,假如去除第一个REORG,语句“ALTER TABLE my_test ALTER COLUMN sla_priority4_time DROP NOT NULL;”就会执行失败。

结论:如果不确定那个是需要REORG哪个是不需要REORG,索性都用上REORG;虽然在允许有三条语句处于Reorg Pending状态,但最好每条ALTER TABLE对应一个REORG,因为处于Reorg Pending状态的表有可能会阻碍后续操作,具体详情请参考文档:http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/c0023297.htm

PS:REORG TABLE本身是DB2的command,不是正常的SQL语句(Statement)。如果在非命令行环境中想使用REORG的话,可以像下面那样调用存储过程间接执行REORG操作,执行前确保你所使用的帐号有调用这个存储过程的权限:

CALL SYSPROC.ADMIN_CMD('reorg table my_test')

这篇文章对你多有用?

相关文章

article delete table 与 truncate table 的区别
TRUNCATE...

(No rating)  6-5-2013    Views: 798   
article How to create a TOC (Table of Contents) from any keyword or phrase in your document
This article explains how to create a TOC...

(No rating)  5-31-2011    Views: 1115   
article Div 与 table 的区别

(No rating)  7-25-2014    Views: 789   

用户评语

添加评语
当前还没有评语.


.: .: .: .: .:
[ 登陆 ]
北京护航科技有限公司 2006

Novots Technologies Limited