[转帖]修复identity 类型字段数据的跳跃(译)
内容提要 <br/><br/>1、引言 <br/>2、dbcc object_atts <br/>3、下载'sp_identity' 存储过程 <br/>4、使用sp_identity显示使用identity 类型字段的表 <br/>5 使用sp_identity显示当前表的 identity 数字 <br/>6、使用sp_identity 修改表的 identity数字 <br/><br/>1引言 <br/>在sybase 中,有一个使用未公开的dbcc 命令 ,即 dbcc object_atts 快速修复identity 跳跃的方法,因为 dbcc <br/><br/>object_atts 比较难于使用,而存储过程 sp_identity 更容易完成你的问题 <br/>警告:本文的方法没有出现在sybase 发布的文档中,并且没有被 sybase 支持,使用与否取决定你自己,如果出现问题,不能从 <br/>sybase 技术支持那里得到帮助 <br/><br/><br/><br/>2、dbcc object_atts <br/>dbcc object_atts 命令提供了 一个访问 OAM 页的后门,在 OMA 中,保存了表的 identity 计数器。 <br/>不幸的是,这个命令在文档中几乎没有任何说明,并且很难使用,其语法如下: <br/> dbcc object_atts (table_name, 0, subcommand, [ new_value ] ) <br/>第一个参数 :表名,第二个参数 0, <br/>第三个参数: get ---显示 保存在 OMA 中的 identity 值 <br/> 或put ---设置 OMA 中的 identity 值,设置的具体数据为 第四个参数数据 <br/>第四个参数 :新设置的数 <br/><br/>主要的问题是 dbcc object_atts 显示的数据为 16字节的 16进制字符,你必须自己解释为10进制,并且,如何解释依赖于 <br/><br/>identity 列的长度,同样,设置它也是。在实际环境中,很少作为首选。 <br/>幸运的是,有一个存储过程 sp_identity 能够处理编码与解码, 并且给出所有含 identity 列的表的情况 <br/><br/>下载 'sp_identity' <br/>sp_identity 只支持 11。0 以后版本,下载文件中包含两个版本,一个用于 ASE 11.9/11.5/11.0 的叫 <br/><br/>,sp_identity.119.sql,另外一个用于ASE 12.0及以后版本(sp_identity.120.sql) <br/><br/>4、使用sp_identity显示使用identity 类型字段的表 <br/>sp_identity 有几个不同的功能,不带任何参数运行,只显示当前数据库中 包含 identity 列的表, <br/>以及最大可能的 identity 跳跃 <br/><br/>1>; sp_identity <br/>2>; go <br/>Tables with an identity column in database '': <br/><br/>Owner.Table.Column datatype Maximum Identity Gap <br/>------------------------------- ------------------------------- <br/>dbo.invoices.inv_nr numeric(18) 500000000000000 (burn) <br/>dbo.small_gap_tab.a numeric(30) 10 (identity_gap) <br/>dbo.my_table.n numeric(6) 500 (burn) <br/><br/><br/>(burn) 表示 identity列的 一次取数由系统参数"identity burning set factor" 决定,而 <br/>(identity_gap) 表示 该表有自定义的identity_gap 属性 <br/><br/><br/>5 使用sp_identity显示当前表的 identity 数字 <br/>确定当前特定表的 OAM 页的identity 值,必须按照以下三步过程: <br/> 首先 打开跟踪标志 3604 (运行 dbcc traceon(3604) ) <br/> 运行 指定特定表名运行 sp_identity <br/><br/> 1>; sp_identity invoices <br/> 2>; go <br/> Table = invoices (id=1804533462) <br/> Identity column = a numeric(18) <br/> Max. Identity Gap = 500000000000000 <br/> ("identity burning set factor" = 5000 = 0.05%) <br/><br/> Reading identity value from OAM page... <br/> object_atts:get:return value=1 <br/> 0207E20C: 0001c6bf 52634001 00000000 00000000 ....Rc@......... <br/> 0207E21C: . <br/> DBCC execution completed. If DBCC printed error messages, <br/> contact a user with System Administrator (SA) role. <br/> <br/> 这个 16字节的 16进制字符串是 OAM 中保存的 identity 值 (0001c6bf 52634001 00000000 00000000) <br/><br/> 再次运行 sp_identity ,并且 指定这个字符串参数 <br/><br/> 1>; sp_identity invoices, "0001c6bf 52634001 00000000 0000000" <br/> 2>; go <br/> Table = invoices (id=1804533462) <br/> Identity column = a numeric(18) <br/> Max. Identity Gap = 500000000000000 <br/> ("identity burning set factor" = 5000 = 0.05%) <br/><br/> Decoded identity value on OAM page = 500000000000001 <br/> (hex=0001c6bf52634001) <br/><br/> 现在,我们得到并解码了 OAM 中的 identity 值,但它意味着什么呢? <br/> 首先,如果你用 "with nowait" 停止服务器,这个 identity 列将跳跃多少。而不是表中数据的下一个。 <br/> 而是保存在 OAM 中的数据加上 identity 种子设顶数(在 ASE 12.0, 为identity_gap 选项) <br/> 另外,当你运行 ASE 12.0, 可以通过运行 dbcc listoam看到这个数据 <br/><br/>6、使用sp_identity 修改表的 identity数字 <br/>使用 sp_identity , OAM 中identity 的 数字可以被设置为任意数. 这个需要如下步骤: <br/>1、确认你要设置的数据(查看表中identity 的数据应该到多少,比如 10033 ) <br/>2、正常停止服务器 <br/>3 重新启动服务器,以单用户模式,或者不让用户访问 <br/>4、 运行 sp_identity table_name, null, new_value ; <br/> 1>; sp_identity invoices, null, 10032 <br/> 2>; go <br/> Table = invoices (id=1804533462) <br/> Identity column = a numeric(18) <br/> Max. Identity Gap = 500000000000000 <br/> ("identity burning set factor" = 5000 = 0.05%) <br/><br/> object_atts:put:return value=1 <br/> DBCC execution completed. If DBCC printed error messages, <br/> contact a user with System Administrator (SA) role. <br/><br/> Identity value on OAM page has been set to 10032 <br/> (hex=0x00000000000027300000000000000000) <br/> You should now do a 'shutdown with nowait' immediately. <br/> After restarting the server, the value assigned to the <br/> next row inserted into 'invoices' will be 10033. <br/><br/>5 然后立即运行 'shutdown with nowait' ,这样 表的下一个 identity 数字是 10033 <br/>6 重新正常启动sybase 服务 <br/><br/><br/><b>说明:如果你应用了 identity 数据类型,并且要求identity 列保持连续,并且数据量很大,那么,用这个方法需要的时间可能比较短 <br/>否则不推荐使用。</b> <br/><br/><br/><br/> <p>下面是SP_IDENTITY.120.SQL,用于 12.0 以后版本 <br/>/* <br/> * SP_IDENTITY.120.SQL - version for ASE 12.0 or later <br/> * (when running ASE 11.9/11.5/11.0, install SP_IDENTITY.119.SQL instead) <br/> * <br/> * Description <br/> * =========== <br/> * This file contains the stored procedure 'sp_identity', which performs some <br/> * useful functions w.r.t. identity columns: <br/> * <br/> * - displays all tables with an identity column in the current database <br/> * - displays the identity value stored on a table's OAM page <br/> * - resets the identity value stored on a table's OAM page <br/> * <br/> * For details and background, see http://www.sypron.nl/idfix.html . <br/> * <br/> * <br/> * Installation <br/> * ============ <br/> * Execute this script using "isql", using a login having both "sa_role" <br/> * and "sso_role". <br/> * The stored procedure will be created in the sybsystemprocs database. <br/> * <br/> * <br/> * Notes <br/> * ===== <br/> * - Traceflag 3604 should be enabled before running sp_identity for a <br/> * specific table ("dbcc traceon(3604)"); if omitted, you won't see <br/> * any output. <br/> * <br/> * - To run sp_identity for a specific table, sa_role and sybase_ts_role <br/> * are required. <br/> * <br/> * - sp_identity was successfully tested on ASE versions 11.0.3, 11.5, <br/> * 11.9.2 and 12.0 on various platforms. <br/> * <br/> * - sp_identity will not work on ASE 11.0 because this version <br/> * does not support the 'case' expression. <br/> * <br/> * - sp_identity was not tested on a 64-bit ASE version. <br/> * <br/> * <br/> * Revision History <br/> * ================ <br/> * Version 1.0 17-Dec-2000 First version <br/> * Version 1.1 Oct-2002 Handle identity_gap=NULL (thanks to Alan Cooper), <br/> * and some small improvements for installation <br/> * Version 1.2 Apr-2003 Improved installation <br/> * <br/> * <br/> * Copyright Note & Disclaimer : <br/> * ============================= <br/> * This software is provided "as is"; there is no warranty of any kind. <br/> * While this software is believed to work accurately, it may not work <br/> * correctly and/or reliably in a production environment. In no event shall <br/> * Rob Verschoor and/or Sypron B.V. be liable for any damages resulting <br/> * from the use of this software. <br/> * You are allowed to use this software free of charge for your own <br/> * professional, non-commercial purposes. <br/> * You are not allowed to sell or bundle this software or use it for any <br/> * other commercial purpose without prior written permission from <br/> * Rob Verschoor/Sypron B.V. <br/> * You may (re)distribute only unaltered copies of this software, which <br/> * must include this copyright note, as well as the copyright note in <br/> * the header of each stored procedure. <br/> * <br/> * Note: All trademarks are acknowledged. <br/> * <br/> * Please send any comments, bugs, suggestions etc. to the below email <br/> * address. <br/> * <br/> * Copyright (c) 2000-2002 Rob Verschoor/Sypron B.V. <br/> * P.O.Box 10695 <br/> * 2501 HR Den Haag <br/> * The Netherlands <br/> * <br/> * Email: rob@sypron.nl <br/> * WWW : http://www.sypron.nl/ <br/> *---------------------------------------------------------------------------- <br/> */ <br/><br/>set nocount on <br/>go <br/>set flushmessage on <br/>go <br/><br/>use sybsystemprocs <br/>go <br/><br/>-- we need to be at ASE 12.0 or later; if not, abort this script <br/>if isnull(object_id("master.dbo.sysqueryplans"),99) >;= 99 <br/>begin <br/> print "" <br/> print "" <br/> print "********************************************" <br/> print "********************************************" <br/> print " This script is for ASE 12.0 or later." <br/> print " Please install SP_IDENTITY.119.SQL instead." <br/> print "********************************************" <br/> print "********************************************" <br/> print " " <br/> print " " <br/> print "" <br/> set background on -- terminate this script now <br/>end <br/>go <br/><br/>print "" <br/>print "Installing 'sp_identity'..." <br/>print "" <br/>go <br/><br/>if object_id("sp_identity_help") <>; NULL <br/>begin <br/> drop proc sp_identity_help <br/>end <br/>go <br/><br/>create proc sp_identity_help <br/>/* Copyright (c) 2000-2002 Rob Verschoor/Sypron B.V. */ <br/>as <br/>begin <br/> print " " <br/> print " Usage: sp_identity table_name, ""hex-string-from-OAM-page"", new-identity-value " <br/> print " Notes: " <br/> print " - specifying only parameter 1 retrieves the current identity value for" <br/> print " that table from the OAM page as a hexadecimal string." <br/> print " - specifying this hexadecimal string as the second parameter (in quotes)" <br/> print " will decode the hex value to a numeric value." <br/> print " - specifying a numeric value for the third parameter will set that" <br/> print " value as the new identity value for this table." <br/> print " - parameters 2 and 3 cannot be specified together: one of them must be NULL." <br/> print " - ""dbcc traceon(3604)"" must be run before using option 2 or 3" <br/> print " " <br/> print " Copyright (c) 2000-2002 Rob Verschoor/Sypron B.V." <br/> print " See http://www.sypron.nl/idfix.html for background information & updates." <br/> print " " <br/>end <br/>go <br/><br/>grant execute on sp_identity_help to public <br/>dump tran sybsystemprocs with truncate_only <br/>go <br/></p> <br/>if object_id("sp_identity") <>; NULL <br/>begin <br/> drop proc sp_identity <br/>end <br/>go <br/><br/>create proc sp_identity <br/>/* Copyright (c) 2000-2002 Rob Verschoor/Sypron B.V. */ <br/> @p0 varchar(50) = NULL, -- table name <br/> @p1 varchar(50) = NULL, -- hex value to decode <br/> @p2 numeric(38) = NULL -- new value to set <br/>as <br/>begin <br/>set nocount on <br/>declare @n numeric(38), @j numeric(38), @n256 numeric(3), @n10 numeric(38) <br/>declare @i int, @max int, @idlen int, @idlenb int, @ib int, @len int <br/>declare @p0_id int, @b int, @b1 binary(1), @lsb int <br/>declare @idgap int, @idburn int, @maxidgap numeric(38), @max1 int, @max2 int <br/>declare @idburnpct numeric(5,2), @v int, @ntab int <br/>declare @c2 char(2), @doampg int, @indid int, @dbname varchar(32) <br/>declare @vc50 varchar(50), @colname varchar(32), @vb16 varbinary(16) <br/><br/>select @dbname = db_name() <br/><br/>-- check version <br/>select @v = 0 <br/>if exists (select * from sysobjects <br/> where name = "sysqueryplans" and type = "S") <br/>begin <br/> select @v = 12 <br/>end <br/><br/>if @p0 = '?' <br/>begin <br/> exec sp_identity_help <br/> return 0 <br/>end <br/><br/>-- numeric values <br/>select @n256 = 256 <br/>select @n10 = 10 <br/><br/>-- id burning set factor <br/>select @idburn = value from master.dbo.syscurconfigs where config=141 <br/>select @idburnpct = convert(numeric(5,2), @idburn * 0.00001) <br/><br/>-- figure out msb/lsb <br/>select @lsb = 0 <br/>if substring(convert(binary(4), 1), 1 ,1) = 0x01 select @lsb = 1 <br/>if substring(convert(binary(4), 1), 2 ,1) = 0x01 select @lsb = 2 <br/>if substring(convert(binary(4), 1), 3 ,1) = 0x01 select @lsb = 3 <br/>if substring(convert(binary(4), 1), 4 ,1) = 0x01 select @lsb = 4 <br/><br/>-- get all tables containing identity columns in this database <br/>select id = so.id, owner = su.name, uid = so.uid, so.name, si.doampg, si.indid, idgap = <br/><br/>isnull(si.identitygap,0), <br/> colname = sc.name, sc.prec, maxgap = convert(numeric(38), ceiling((@idburn * 0.0000001) * <br/><br/>power(@n10,prec))) <br/>into #id <br/>from sysindexes si, syscolumns sc, sysobjects so, sysusers su <br/>where si.indid < 2 <br/> and so.type = "U" <br/> and sc.status & 128 = 128 <br/> and so.id = sc.id <br/> and so.id = si.id <br/> and so.uid = su.uid <br/>select @ntab = @@rowcount <br/><br/>set arithabort numeric_truncation off <br/><br/>if @p0 = null <br/>begin <br/> -- display all tables with identity columns in the current DB <br/> if @ntab = 0 <br/> begin <br/> print " There are no tables with an identity column in database '%1!'", @dbname <br/> return 0 <br/> end <br/> print " Tables with an identity column in database '%1!':", @dbname <br/> print " " <br/> select @max1 = max(char_length(owner + "." + name + "." + colname)) + 12 from #id <br/> select @max2 = max(char_length(convert(varchar(38), maxgap))) + 7 from #id <br/><br/> if @max1 <= 52 and @max2 <= 24 <br/> begin <br/> select convert(varchar(52), owner + "." + name + "." + colname + " numeric(" + <br/><br/>convert(varchar(2),prec) + ")") "Owner.Table.Column datatype", <br/> convert(varchar(24), case when idgap = 0 then convert(varchar(38),maxgap) + " <br/><br/>(burn)" <br/> else convert(varchar, idgap) + " (identity_gap)" <br/> end) "Maximum Identity Gap" <br/><br/> from #id <br/> order by name <br/> end <br/> else <br/> if @max1 <= 32 and @max2 <= 44 <br/> begin <br/> select convert(varchar(32), owner + "." + name + "." + colname + " numeric(" + <br/><br/>convert(varchar(2),prec) + ")") "Owner.Table.Column datatype", <br/> convert(varchar(44), case when idgap = 0 then convert(varchar(38),maxgap) + " <br/><br/>(burn)" <br/> else convert(varchar, idgap) + " (identity_gap)" <br/> end) "Maximum Identity Gap" <br/><br/> from #id <br/> order by name <br/> end <br/> else <br/> begin <br/> select convert(varchar(78), owner + "." + name + "." + colname + " numeric(" + <br/><br/>convert(varchar(2),prec) + ")") "Owner.Table.Column datatype", <br/> convert(varchar(50), case when idgap = 0 then convert(varchar(38),maxgap) + " <br/><br/>(burn)" <br/> else convert(varchar, idgap) + " (identity_gap)" <br/> end) "Maximum Identity Gap" <br/> from #id <br/> order by name <br/> end <br/><br/> print " " <br/> print " Legend:" <br/> print " (burn) : gap size is determined by ""identity burning set factor"" " <br/> if @v = 12 <br/> begin <br/> print " (identity_gap) : gap size is determined by the ""identity_gap"" setting" <br/> end <br/> print " " <br/> print " Current value for ""identity burning set factor"" = %1! (=%2!%%)", @idburn, @idburnpct <br/><br/><br/> return 0 <br/>end <br/><br/>if charindex("sa_role", show_role()) = 0 <br/>begin <br/> print "You must have 'sa_role' to run this procedure." <br/> return -1 <br/>end <br/><br/>if charindex("sybase_ts_role", show_role()) = 0 <br/>begin <br/> print "You must have 'sybase_ts_role' to run this procedure." <br/> return -1 <br/>end <br/><br/>-- get some info on the object <br/>select @p0_id = object_id(@p0) <br/>if @p0_id = NULL <br/>begin <br/> print " Error: '%1!' is not a user table.", @p0 <br/> return -1 <br/>end <br/><br/>if @p0 not like "%.%" <br/>begin <br/> select @ntab = count(*) from sysobjects where name = @p0 and type = "U" <br/><br/> if @ntab >; 1 <br/> begin <br/> print " %1! tables named '%2!' exist in this database:", @ntab, @p0 <br/> print " " <br/> select owner + "." + name "owner.table_name" <br/> from #id where name = @p0 order by uid <br/> print " " <br/> print " Specify 'owner.table_name' to identify the table." <br/> return -1 <br/> end <br/>end <br/><br/>select @doampg = doampg, @indid = indid, @idgap = idgap <br/>from #id where id = @p0_id <br/><br/>if not exists (select 1 from syscolumns where id = @p0_id and status & 128 = 128) <br/>begin <br/> print " Error: Table '%1!' does not have an identity column", @p0 <br/> return -1 <br/>end <br/><br/>-- retrieve the length of the numeric identity column as declared when the <br/>-- table was created <br/>select @len = prec, @colname = name <br/>from syscolumns where id = @p0_id and status & 128 = 128 <br/>if @@rowcount = 0 <br/>begin <br/> print " Error: Could not retrieve length of identity column for table '%1!'", @p0 <br/> return -1 <br/>end <br/><br/>select @idlen = @len -- column precision (positions) <br/>select @idlenb = (@idlen+1-((@idlen+5)/12)-(@idlen/12))/2 -- column length (bytes) <br/> <br/>print " " <br/>print " Table = %1! (id=%2!)", @p0, @p0_id <br/>print " Identity column = %1! numeric(%2!)", @colname, @len <br/>--print " OAM page = %1!", @doampg <br/>--print " Bytes on OAM page = %1!", @idlenb <br/>if @idgap >; 0 <br/>begin <br/> print " Max. Identity Gap = %1! (""identity_gap"" = %2!)", @idgap, @idgap <br/>end <br/>else <br/>begin <br/> set arithabort numeric_truncation off <br/> select @maxidgap = ceiling((convert(numeric(38),@idburn) * 0.0000001) * power(@n10,@len)) <br/> print " Max. Identity Gap = %1!", @maxidgap <br/> print " (""identity burning set factor"" = %1! = %2!%%)", @idburn, @idburnpct <br/> if @v = 12 <br/> begin <br/> print " (Note: ""identity_gap"" has not been set for this table !)" <br/> end <br/>end <br/>print " " <br/><br/>if @p1 = NULL and @p2 = NULL -- retrieve current ID value <br/>begin <br/> print " " <br/> print " Reading identity value from OAM page... (traceflag 3604 should be enabled !)" <br/> print " " <br/> dbcc object_atts (@p0, 0, get) <br/> print " " <br/> print " To decode this hexadecimal value, re-run 'sp_identity' with the hexadecimal" <br/> print " string as a quoted 2nd parameter (you can leave the spaces in). " <br/> print " Example: sp_identity %1!, ""the-hex-string-from-the-above-output"" ", @p0 <br/> print " " <br/> -- <br/> -- only for 12.0+, dbcc listoam will display the values in the OAM and the DES <br/> -- <br/> --dbcc listoam(@dbname, @p0_id, @indid) <br/> -- <br/> return 0 <br/>end <br/><br/>if upper(@p1) like "[ 0-9A-F]%" -- entered a hex string, decode it <br/>begin <br/><br/>if @p2 != NULL <br/>begin <br/> print " Error: When decoding a hex value from the OAM page, parameter 3" <br/> print " (the new identity value) must be NULL." <br/> exec sp_identity_help <br/> return -1 <br/>end <br/><br/>select @ib = @idlenb -- counts bytes <br/>select @i = char_length(@p1) -- counts string <br/>select @n = 0 -- holds result <br/><br/>while 1 = 1 <br/>begin <br/> select @c2 = substring(@p1, (char_length(@p1)-@i)+1, 2) <br/><br/> --print "Step %1!, [%2!]", @ib, @c2 <br/> if upper(substring(@c2,1,1)) = " " -- ignore single space pasted in by user <br/> begin <br/> select @i = @i - 1 <br/> continue <br/> end <br/><br/> if (upper(@c2) not like "") <br/> begin <br/> print " Error: Invalid characters (%1!) in hex string", @c2 <br/> break <br/> end <br/><br/> -- add this byte to the result <br/> select @vc50 = @vc50 + @c2 <br/> select @j = power(@n256, (@ib-1)) <br/> select @n = @n + @j * hextoint("0x" + @c2) <br/> --print "Step %1!, exp= %2!, result = %3!", @ib, @j, @n <br/><br/> -- next byte <br/> select @ib = @ib - 1 <br/> if @ib = 0 break -- ready <br/><br/> -- next 2 chars <br/> select @i = @i - 2 <br/> if @i = 0 <br/> begin <br/> -- we shouldn't have got here, error <br/> print " Error: ID column length and specified hex string do not match !" <br/> break <br/> end <br/>end <br/><br/>if @ib = 0 <br/>begin <br/> print " Decoded identity value on OAM page = %1!", @n <br/> print " (hex= %1!)", @vc50 <br/> print " " <br/> return 0 <br/>end <br/>else <br/>begin <br/> print " Error: Aborted due to error." <br/> return -1 <br/>end <br/>end <br/><br/>if @p2 != NULL -- entered a new ID value, set it <br/>begin <br/><br/>if @p1 != NULL <br/>begin <br/> print " Error: When setting a new identity value, parameter 2" <br/> print " (the hex string from the OAM page) must be NULL." <br/> exec sp_identity_help <br/> return -1 <br/>end <br/><br/>-- set the new ID value <br/>if @p2 <= 0 <br/>begin <br/> print " Error: The new identity value must be >;= 0." <br/> print " " <br/> exec sp_identity_help <br/> return -1 <br/>end <br/><br/>if char_length(convert(varchar, @p2)) >; @idlen <br/>begin <br/> select @vc50 = replicate("9", @idlen) <br/> print " Error: New identity value (%1!) is too large", @p2 <br/> print " for this identity column. The maximum possible value", @p2 <br/> print " is %1! (%2! positions).", @vc50, @idlen <br/> return -1 <br/>end <br/><br/>if @lsb = 0 <br/>begin <br/> print " " <br/> print "Internal error in 'sp_identity':" <br/> print "Cannot figure out byte order on this platform." <br/> print "Please send a note to 'rob@sypron.nl' with the text of this" <br/> print "error and your @@version string." <br/> return -1 <br/>end <br/><br/>-- convert the numeric value to hex <br/>select @ib = @idlenb -- counts bytes <br/>select @i = 15 <br/><br/>select @vc50 = NULL -- holds result <br/>select @vb16 = NULL -- holds result <br/>select @n256 = 256 <br/>select @n = @p2 <br/>set arithabort numeric_truncation off <br/><br/>while 1 = 1 <br/>begin <br/> select @j = power(@n256, @i) <br/><br/> select @b = @n / @j <br/> select @n = @n - (@b * @j) <br/> select @c2 = right(inttohex(@b),2) <br/> select @b1 = substring(convert(binary(4), @b), @lsb,1) <br/><br/> select @vb16 = @vb16 + @b1 <br/><br/> --print "Step %1!, @b=%2!, hex(c2)=%3!, hex(b1)=%5!, result=%4!", @i, @b, @c2, @vb16, @b1 <br/><br/> select @i = @i - 1 <br/> if @i < 0 break -- ready <br/>end <br/><br/>if @i < 0 <br/>begin <br/> select @vb16 = substring(@vb16, 16 - (@idlenb) + 1, (@idlenb) ) + substring(@vb16, 1, 16 - <br/><br/>(@idlenb) ) <br/><br/> -- set the new ID value <br/> dbcc object_atts(@p0, 0, "put", @vb16) <br/><br/> print " " <br/> print " Identity value on OAM page has been set to %1!", @p2 <br/> print " (hex= %1!)", @vb16 <br/> print " " <br/> select @p2 = @p2 + 1 <br/> print " You should now do a 'shutdown with nowait' immediately." <br/> print " After restarting the server, the value assigned to the next row " <br/> print " inserted into '%1!' will be %2!.", @p0, @p2 <br/> print " " <br/> return 0 <br/>end <br/>else <br/>begin <br/> print " Error: Aborted due to error." <br/> return -1 <br/>end <br/> <br/>end <br/><br/>-- we should never get here <br/>print "Internal error in 'sp_identity': Reached invalid end of procedure." <br/>return -1 <br/>end <br/>go <br/><br/>grant execute on sp_identity to public <br/>dump tran sybsystemprocs with truncate_only <br/>go <br/><br/><br/>print "Ready. For usage information, run 'sp_identity ""?"" '." <br/>print "" <br/>go <br/><br/>/* <br/>** end <br/>*/<br/> 有谁用过吗,给提点意见或建议,使用这个存储过程安全吗?!
页:
[1]