转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> SyBase >> 正文
修复identity 类型字段数据的跳跃(译)         ★★★★

修复identity 类型字段数据的跳跃(译)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:4387 更新时间:2009/4/22 23:09:38

修复identity 类型字段数据的跳跃(译)
 
内容提要

1、引言
2、dbcc object_atts 
3、下载'sp_identity' 存储过程
4、使用sp_identity显示使用identity 类型字段的表
5  使用sp_identity显示当前表的 identity 数字
6、使用sp_identity 修改表的 identity数字

1引言
在sybase 中,有一个使用未公开的dbcc 命令 ,即 dbcc object_atts 快速修复identity 跳跃的方法,因为 dbcc 

object_atts 比较难于使用,而存储过程 sp_identity 更容易完成你的问题
警告:本文的方法没有出现在sybase 发布的文档中,并且没有被 sybase 支持,使用与否取决定你自己,如果出现问题,不能从
sybase 技术支持那里得到帮助



2、dbcc object_atts
dbcc object_atts 命令提供了 一个访问 OAM 页的后门,在 OMA 中,保存了表的 identity 计数器。
不幸的是,这个命令在文档中几乎没有任何说明,并且很难使用,其语法如下:
  dbcc object_atts (table_name, 0, subcommand, [ new_value ] )
第一个参数 :表名,第二个参数 0,
第三个参数:   get  ---显示 保存在 OMA 中的 identity 值
           或put  ---设置 OMA 中的 identity 值,设置的具体数据为 第四个参数数据
第四个参数 :新设置的数

主要的问题是 dbcc object_atts 显示的数据为 16字节的 16进制字符,你必须自己解释为10进制,并且,如何解释依赖于 

identity 列的长度,同样,设置它也是。在实际环境中,很少作为首选。
幸运的是,有一个存储过程 sp_identity 能够处理编码与解码, 并且给出所有含 identity 列的表的情况

下载 'sp_identity'
sp_identity 只支持 11。0 以后版本,下载文件中包含两个版本,一个用于 ASE 11.9/11.5/11.0 的叫  

,sp_identity.119.sql,另外一个用于ASE 12.0及以后版本(sp_identity.120.sql)

4、使用sp_identity显示使用identity 类型字段的表
sp_identity 有几个不同的功能,不带任何参数运行,只显示当前数据库中 包含 identity 列的表,
以及最大可能的 identity 跳跃

1> sp_identity
2> go
Tables with an identity column in database '':

Owner.Table.Column datatype     Maximum Identity Gap
------------------------------- -------------------------------
dbo.invoices.inv_nr numeric(18) 500000000000000 (burn)
dbo.small_gap_tab.a numeric(30) 10 (identity_gap)
dbo.my_table.n numeric(6)       500 (burn)


(burn) 表示 identity列的 一次取数由系统参数"identity burning set factor" 决定,而
(identity_gap) 表示 该表有自定义的identity_gap 属性


5  使用sp_identity显示当前表的 identity 数字
确定当前特定表的  OAM 页的identity 值,必须按照以下三步过程:
  首先 打开跟踪标志 3604 (运行 dbcc traceon(3604) )
  运行 指定特定表名运行 sp_identity 

  1> sp_identity invoices
  2> go
  Table             = invoices (id=1804533462)
  Identity column   = a numeric(18)
  Max. Identity Gap = 500000000000000
         ("identity burning set factor" = 5000 = 0.05%)

  Reading identity value from OAM page... 
  object_atts:get:return value=1
  0207E20C: 0001c6bf 52634001 00000000 00000000 ....Rc@.........
  0207E21C: .
  DBCC execution completed. If DBCC printed error messages, 
  contact a user with System Administrator (SA) role.
  
  这个 16字节的 16进制字符串是 OAM 中保存的 identity 值 (0001c6bf 52634001 00000000 00000000)

  再次运行 sp_identity ,并且 指定这个字符串参数

  1> sp_identity invoices, "0001c6bf 52634001 00000000 0000000"
  2> go
  Table             = invoices (id=1804533462)
  Identity column   = a numeric(18)
  Max. Identity Gap = 500000000000000
         ("identity burning set factor" = 5000 = 0.05%)

  Decoded identity value on OAM page = 500000000000001
  (hex=0001c6bf52634001)

  现在,我们得到并解码了 OAM 中的 identity 值,但它意味着什么呢?
  首先,如果你用 "with nowait" 停止服务器,这个 identity 列将跳跃多少。而不是表中数据的下一个。
  而是保存在 OAM 中的数据加上 identity 种子设顶数(在 ASE 12.0, 为identity_gap 选项)
  另外,当你运行 ASE 12.0, 可以通过运行 dbcc listoam看到这个数据   

6、使用sp_identity 修改表的 identity数字
使用 sp_identity , OAM 中identity 的 数字可以被设置为任意数. 这个需要如下步骤:
1、确认你要设置的数据(查看表中identity 的数据应该到多少,比如 10033 )
2、正常停止服务器
3  重新启动服务器,以单用户模式,或者不让用户访问
4、 运行 sp_identity table_name, null, new_value ; 
  1> sp_identity invoices, null, 10032
  2> go
  Table             = invoices (id=1804533462)
  Identity column   = a numeric(18)
  Max. Identity Gap = 500000000000000
       ("identity burning set factor" = 5000 = 0.05%)

  object_atts:put:return value=1
  DBCC execution completed. If DBCC printed error messages, 
  contact a user with System Administrator (SA) role.

  Identity value on OAM page has been set to 10032
  (hex=0x00000000000027300000000000000000)
  You should now do a 'shutdown with nowait' immediately.
  After restarting the server, the value assigned to the 
  next row inserted into 'invoices' will be 10033.

5  然后立即运行 'shutdown with nowait' ,这样 表的下一个  identity 数字是 10033 
6  重新正常启动sybase 服务 


[color=red][b]说明:如果你应用了 identity 数据类型,并且要求identity 列保持连续,并且数据量很大,那么,用这个方法需要的时间可能比较短
否则不推荐使用。[/b][/color]



下面是SP_IDENTITY.120.SQL,用于  12.0 以后版本
/* 
 * SP_IDENTITY.120.SQL - version for ASE 12.0 or later
 * (when running ASE 11.9/11.5/11.0, install SP_IDENTITY.119.SQL instead)
 * 
 * Description
 * ===========
 * This file contains the stored procedure 'sp_identity', which performs some 
 * useful functions w.r.t. identity columns:
 *
 *   - displays all tables with an identity column in the current database
 *   - displays the identity value stored on a table's OAM page
 *   - resets the identity value stored on a table's OAM page
 *
 * For details and background, see http://www.sypron.nl/idfix.html .
 *
 *
 * Installation
 * ============
 * Execute this script using "isql", using a login having both "sa_role"
 * and "sso_role".
 * The stored procedure will be created in the sybsystemprocs database.
 *
 *
 * Notes
 * =====
 * - Traceflag 3604 should be enabled before running sp_identity for a 
 *   specific table ("dbcc traceon(3604)"); if omitted, you won't see 
 *   any output.
 *
 * - To run sp_identity for a specific table, sa_role and sybase_ts_role 
 *   are required.
 *
 * - sp_identity was successfully tested on ASE versions 11.0.3, 11.5, 
 *   11.9.2 and 12.0 on various platforms.
 *
 * - sp_identity will not work on ASE 11.0 because this version 
 *   does not support the 'case' expression.
 *
 * - sp_identity was not tested on a 64-

[1] [2] [3] [4] [5]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台