阿辉 发表于 2006-4-14 13:21:13

[转帖]修复identity 类型字段数据的跳跃(译)

内容提要 <br/><br/>1、引言 <br/>2、dbcc&nbsp;object_atts&nbsp; <br/>3、下载'sp_identity'&nbsp;存储过程 <br/>4、使用sp_identity显示使用identity&nbsp;类型字段的表 <br/>5&nbsp;&nbsp;使用sp_identity显示当前表的&nbsp;identity&nbsp;数字 <br/>6、使用sp_identity&nbsp;修改表的&nbsp;identity数字 <br/><br/>1引言 <br/>在sybase&nbsp;中,有一个使用未公开的dbcc&nbsp;命令&nbsp;,即&nbsp;dbcc&nbsp;object_atts&nbsp;快速修复identity&nbsp;跳跃的方法,因为&nbsp;dbcc&nbsp; <br/><br/>object_atts&nbsp;比较难于使用,而存储过程&nbsp;sp_identity&nbsp;更容易完成你的问题 <br/>警告:本文的方法没有出现在sybase&nbsp;发布的文档中,并且没有被&nbsp;sybase&nbsp;支持,使用与否取决定你自己,如果出现问题,不能从 <br/>sybase&nbsp;技术支持那里得到帮助 <br/><br/><br/><br/>2、dbcc&nbsp;object_atts <br/>dbcc&nbsp;object_atts&nbsp;命令提供了&nbsp;一个访问&nbsp;OAM&nbsp;页的后门,在&nbsp;OMA&nbsp;中,保存了表的&nbsp;identity&nbsp;计数器。 <br/>不幸的是,这个命令在文档中几乎没有任何说明,并且很难使用,其语法如下: <br/>&nbsp;&nbsp;dbcc&nbsp;object_atts&nbsp;(table_name,&nbsp;0,&nbsp;subcommand,&nbsp;[&nbsp;new_value&nbsp;]&nbsp;) <br/>第一个参数&nbsp;:表名,第二个参数&nbsp;0, <br/>第三个参数:&nbsp;&nbsp;&nbsp;get&nbsp;&nbsp;---显示&nbsp;保存在&nbsp;OMA&nbsp;中的&nbsp;identity&nbsp;值 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;或put&nbsp;&nbsp;---设置&nbsp;OMA&nbsp;中的&nbsp;identity&nbsp;值,设置的具体数据为&nbsp;第四个参数数据 <br/>第四个参数&nbsp;:新设置的数 <br/><br/>主要的问题是&nbsp;dbcc&nbsp;object_atts&nbsp;显示的数据为&nbsp;16字节的&nbsp;16进制字符,你必须自己解释为10进制,并且,如何解释依赖于&nbsp; <br/><br/>identity&nbsp;列的长度,同样,设置它也是。在实际环境中,很少作为首选。 <br/>幸运的是,有一个存储过程&nbsp;sp_identity&nbsp;能够处理编码与解码,&nbsp;并且给出所有含&nbsp;identity&nbsp;列的表的情况 <br/><br/>下载&nbsp;'sp_identity' <br/>sp_identity&nbsp;只支持&nbsp;11。0&nbsp;以后版本,下载文件中包含两个版本,一个用于&nbsp;ASE&nbsp;11.9/11.5/11.0&nbsp;的叫&nbsp;&nbsp; <br/><br/>,sp_identity.119.sql,另外一个用于ASE&nbsp;12.0及以后版本(sp_identity.120.sql) <br/><br/>4、使用sp_identity显示使用identity&nbsp;类型字段的表 <br/>sp_identity&nbsp;有几个不同的功能,不带任何参数运行,只显示当前数据库中&nbsp;包含&nbsp;identity&nbsp;列的表, <br/>以及最大可能的&nbsp;identity&nbsp;跳跃 <br/><br/>1&gt;;&nbsp;sp_identity <br/>2&gt;;&nbsp;go <br/>Tables&nbsp;with&nbsp;an&nbsp;identity&nbsp;column&nbsp;in&nbsp;database&nbsp;'': <br/><br/>Owner.Table.Column&nbsp;datatype&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Maximum&nbsp;Identity&nbsp;Gap <br/>-------------------------------&nbsp;------------------------------- <br/>dbo.invoices.inv_nr&nbsp;numeric(18)&nbsp;500000000000000&nbsp;(burn) <br/>dbo.small_gap_tab.a&nbsp;numeric(30)&nbsp;10&nbsp;(identity_gap) <br/>dbo.my_table.n&nbsp;numeric(6)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;500&nbsp;(burn) <br/><br/><br/>(burn)&nbsp;表示&nbsp;identity列的&nbsp;一次取数由系统参数"identity&nbsp;burning&nbsp;set&nbsp;factor"&nbsp;决定,而 <br/>(identity_gap)&nbsp;表示&nbsp;该表有自定义的identity_gap&nbsp;属性 <br/><br/><br/>5&nbsp;&nbsp;使用sp_identity显示当前表的&nbsp;identity&nbsp;数字 <br/>确定当前特定表的&nbsp;&nbsp;OAM&nbsp;页的identity&nbsp;值,必须按照以下三步过程: <br/>&nbsp;&nbsp;首先&nbsp;打开跟踪标志&nbsp;3604&nbsp;(运行&nbsp;dbcc&nbsp;traceon(3604)&nbsp;) <br/>&nbsp;&nbsp;运行&nbsp;指定特定表名运行&nbsp;sp_identity&nbsp; <br/><br/>&nbsp;&nbsp;1&gt;;&nbsp;sp_identity&nbsp;invoices <br/>&nbsp;&nbsp;2&gt;;&nbsp;go <br/>&nbsp;&nbsp;Table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;invoices&nbsp;(id=1804533462) <br/>&nbsp;&nbsp;Identity&nbsp;column&nbsp;&nbsp;&nbsp;=&nbsp;a&nbsp;numeric(18) <br/>&nbsp;&nbsp;Max.&nbsp;Identity&nbsp;Gap&nbsp;=&nbsp;500000000000000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;("identity&nbsp;burning&nbsp;set&nbsp;factor"&nbsp;=&nbsp;5000&nbsp;=&nbsp;0.05%) <br/><br/>&nbsp;&nbsp;Reading&nbsp;identity&nbsp;value&nbsp;from&nbsp;OAM&nbsp;page...&nbsp; <br/>&nbsp;&nbsp;object_atts:get:return&nbsp;value=1 <br/>&nbsp;&nbsp;0207E20C:&nbsp;0001c6bf&nbsp;52634001&nbsp;00000000&nbsp;00000000&nbsp;....Rc@......... <br/>&nbsp;&nbsp;0207E21C:&nbsp;. <br/>&nbsp;&nbsp;DBCC&nbsp;execution&nbsp;completed.&nbsp;If&nbsp;DBCC&nbsp;printed&nbsp;error&nbsp;messages,&nbsp; <br/>&nbsp;&nbsp;contact&nbsp;a&nbsp;user&nbsp;with&nbsp;System&nbsp;Administrator&nbsp;(SA)&nbsp;role. <br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;这个&nbsp;16字节的&nbsp;16进制字符串是&nbsp;OAM&nbsp;中保存的&nbsp;identity&nbsp;值&nbsp;(0001c6bf&nbsp;52634001&nbsp;00000000&nbsp;00000000) <br/><br/>&nbsp;&nbsp;再次运行&nbsp;sp_identity&nbsp;,并且&nbsp;指定这个字符串参数 <br/><br/>&nbsp;&nbsp;1&gt;;&nbsp;sp_identity&nbsp;invoices,&nbsp;"0001c6bf&nbsp;52634001&nbsp;00000000&nbsp;0000000" <br/>&nbsp;&nbsp;2&gt;;&nbsp;go <br/>&nbsp;&nbsp;Table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;invoices&nbsp;(id=1804533462) <br/>&nbsp;&nbsp;Identity&nbsp;column&nbsp;&nbsp;&nbsp;=&nbsp;a&nbsp;numeric(18) <br/>&nbsp;&nbsp;Max.&nbsp;Identity&nbsp;Gap&nbsp;=&nbsp;500000000000000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;("identity&nbsp;burning&nbsp;set&nbsp;factor"&nbsp;=&nbsp;5000&nbsp;=&nbsp;0.05%) <br/><br/>&nbsp;&nbsp;Decoded&nbsp;identity&nbsp;value&nbsp;on&nbsp;OAM&nbsp;page&nbsp;=&nbsp;500000000000001 <br/>&nbsp;&nbsp;(hex=0001c6bf52634001) <br/><br/>&nbsp;&nbsp;现在,我们得到并解码了&nbsp;OAM&nbsp;中的&nbsp;identity&nbsp;值,但它意味着什么呢? <br/>&nbsp;&nbsp;首先,如果你用&nbsp;"with&nbsp;nowait"&nbsp;停止服务器,这个&nbsp;identity&nbsp;列将跳跃多少。而不是表中数据的下一个。 <br/>&nbsp;&nbsp;而是保存在&nbsp;OAM&nbsp;中的数据加上&nbsp;identity&nbsp;种子设顶数(在&nbsp;ASE&nbsp;12.0,&nbsp;为identity_gap&nbsp;选项) <br/>&nbsp;&nbsp;另外,当你运行&nbsp;ASE&nbsp;12.0,&nbsp;可以通过运行&nbsp;dbcc&nbsp;listoam看到这个数据&nbsp;&nbsp;&nbsp; <br/><br/>6、使用sp_identity&nbsp;修改表的&nbsp;identity数字 <br/>使用&nbsp;sp_identity&nbsp;,&nbsp;OAM&nbsp;中identity&nbsp;的&nbsp;数字可以被设置为任意数.&nbsp;这个需要如下步骤: <br/>1、确认你要设置的数据(查看表中identity&nbsp;的数据应该到多少,比如&nbsp;10033&nbsp;) <br/>2、正常停止服务器 <br/>3&nbsp;&nbsp;重新启动服务器,以单用户模式,或者不让用户访问 <br/>4、&nbsp;运行&nbsp;sp_identity&nbsp;table_name,&nbsp;null,&nbsp;new_value&nbsp;;&nbsp; <br/>&nbsp;&nbsp;1&gt;;&nbsp;sp_identity&nbsp;invoices,&nbsp;null,&nbsp;10032 <br/>&nbsp;&nbsp;2&gt;;&nbsp;go <br/>&nbsp;&nbsp;Table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;invoices&nbsp;(id=1804533462) <br/>&nbsp;&nbsp;Identity&nbsp;column&nbsp;&nbsp;&nbsp;=&nbsp;a&nbsp;numeric(18) <br/>&nbsp;&nbsp;Max.&nbsp;Identity&nbsp;Gap&nbsp;=&nbsp;500000000000000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;("identity&nbsp;burning&nbsp;set&nbsp;factor"&nbsp;=&nbsp;5000&nbsp;=&nbsp;0.05%) <br/><br/>&nbsp;&nbsp;object_atts:put:return&nbsp;value=1 <br/>&nbsp;&nbsp;DBCC&nbsp;execution&nbsp;completed.&nbsp;If&nbsp;DBCC&nbsp;printed&nbsp;error&nbsp;messages,&nbsp; <br/>&nbsp;&nbsp;contact&nbsp;a&nbsp;user&nbsp;with&nbsp;System&nbsp;Administrator&nbsp;(SA)&nbsp;role. <br/><br/>&nbsp;&nbsp;Identity&nbsp;value&nbsp;on&nbsp;OAM&nbsp;page&nbsp;has&nbsp;been&nbsp;set&nbsp;to&nbsp;10032 <br/>&nbsp;&nbsp;(hex=0x00000000000027300000000000000000) <br/>&nbsp;&nbsp;You&nbsp;should&nbsp;now&nbsp;do&nbsp;a&nbsp;'shutdown&nbsp;with&nbsp;nowait'&nbsp;immediately. <br/>&nbsp;&nbsp;After&nbsp;restarting&nbsp;the&nbsp;server,&nbsp;the&nbsp;value&nbsp;assigned&nbsp;to&nbsp;the&nbsp; <br/>&nbsp;&nbsp;next&nbsp;row&nbsp;inserted&nbsp;into&nbsp;'invoices'&nbsp;will&nbsp;be&nbsp;10033. <br/><br/>5&nbsp;&nbsp;然后立即运行&nbsp;'shutdown&nbsp;with&nbsp;nowait'&nbsp;,这样&nbsp;表的下一个&nbsp;&nbsp;identity&nbsp;数字是&nbsp;10033&nbsp; <br/>6&nbsp;&nbsp;重新正常启动sybase&nbsp;服务&nbsp; <br/><br/><br/><b>说明:如果你应用了&nbsp;identity&nbsp;数据类型,并且要求identity&nbsp;列保持连续,并且数据量很大,那么,用这个方法需要的时间可能比较短 <br/>否则不推荐使用。</b> <br/><br/><br/><br/>

阿辉 发表于 2006-4-14 13:22:48

<p>下面是SP_IDENTITY.120.SQL,用于&nbsp;&nbsp;12.0&nbsp;以后版本 <br/>/*&nbsp; <br/>&nbsp;*&nbsp;SP_IDENTITY.120.SQL&nbsp;-&nbsp;version&nbsp;for&nbsp;ASE&nbsp;12.0&nbsp;or&nbsp;later <br/>&nbsp;*&nbsp;(when&nbsp;running&nbsp;ASE&nbsp;11.9/11.5/11.0,&nbsp;install&nbsp;SP_IDENTITY.119.SQL&nbsp;instead) <br/>&nbsp;*&nbsp; <br/>&nbsp;*&nbsp;Description <br/>&nbsp;*&nbsp;=========== <br/>&nbsp;*&nbsp;This&nbsp;file&nbsp;contains&nbsp;the&nbsp;stored&nbsp;procedure&nbsp;'sp_identity',&nbsp;which&nbsp;performs&nbsp;some&nbsp; <br/>&nbsp;*&nbsp;useful&nbsp;functions&nbsp;w.r.t.&nbsp;identity&nbsp;columns: <br/>&nbsp;* <br/>&nbsp;*&nbsp;&nbsp;&nbsp;-&nbsp;displays&nbsp;all&nbsp;tables&nbsp;with&nbsp;an&nbsp;identity&nbsp;column&nbsp;in&nbsp;the&nbsp;current&nbsp;database <br/>&nbsp;*&nbsp;&nbsp;&nbsp;-&nbsp;displays&nbsp;the&nbsp;identity&nbsp;value&nbsp;stored&nbsp;on&nbsp;a&nbsp;table's&nbsp;OAM&nbsp;page <br/>&nbsp;*&nbsp;&nbsp;&nbsp;-&nbsp;resets&nbsp;the&nbsp;identity&nbsp;value&nbsp;stored&nbsp;on&nbsp;a&nbsp;table's&nbsp;OAM&nbsp;page <br/>&nbsp;* <br/>&nbsp;*&nbsp;For&nbsp;details&nbsp;and&nbsp;background,&nbsp;see&nbsp;http://www.sypron.nl/idfix.html&nbsp;. <br/>&nbsp;* <br/>&nbsp;* <br/>&nbsp;*&nbsp;Installation <br/>&nbsp;*&nbsp;============ <br/>&nbsp;*&nbsp;Execute&nbsp;this&nbsp;script&nbsp;using&nbsp;"isql",&nbsp;using&nbsp;a&nbsp;login&nbsp;having&nbsp;both&nbsp;"sa_role" <br/>&nbsp;*&nbsp;and&nbsp;"sso_role". <br/>&nbsp;*&nbsp;The&nbsp;stored&nbsp;procedure&nbsp;will&nbsp;be&nbsp;created&nbsp;in&nbsp;the&nbsp;sybsystemprocs&nbsp;database. <br/>&nbsp;* <br/>&nbsp;* <br/>&nbsp;*&nbsp;Notes <br/>&nbsp;*&nbsp;===== <br/>&nbsp;*&nbsp;-&nbsp;Traceflag&nbsp;3604&nbsp;should&nbsp;be&nbsp;enabled&nbsp;before&nbsp;running&nbsp;sp_identity&nbsp;for&nbsp;a&nbsp; <br/>&nbsp;*&nbsp;&nbsp;&nbsp;specific&nbsp;table&nbsp;("dbcc&nbsp;traceon(3604)");&nbsp;if&nbsp;omitted,&nbsp;you&nbsp;won't&nbsp;see&nbsp; <br/>&nbsp;*&nbsp;&nbsp;&nbsp;any&nbsp;output. <br/>&nbsp;* <br/>&nbsp;*&nbsp;-&nbsp;To&nbsp;run&nbsp;sp_identity&nbsp;for&nbsp;a&nbsp;specific&nbsp;table,&nbsp;sa_role&nbsp;and&nbsp;sybase_ts_role&nbsp; <br/>&nbsp;*&nbsp;&nbsp;&nbsp;are&nbsp;required. <br/>&nbsp;* <br/>&nbsp;*&nbsp;-&nbsp;sp_identity&nbsp;was&nbsp;successfully&nbsp;tested&nbsp;on&nbsp;ASE&nbsp;versions&nbsp;11.0.3,&nbsp;11.5,&nbsp; <br/>&nbsp;*&nbsp;&nbsp;&nbsp;11.9.2&nbsp;and&nbsp;12.0&nbsp;on&nbsp;various&nbsp;platforms. <br/>&nbsp;* <br/>&nbsp;*&nbsp;-&nbsp;sp_identity&nbsp;will&nbsp;not&nbsp;work&nbsp;on&nbsp;ASE&nbsp;11.0&nbsp;because&nbsp;this&nbsp;version&nbsp; <br/>&nbsp;*&nbsp;&nbsp;&nbsp;does&nbsp;not&nbsp;support&nbsp;the&nbsp;'case'&nbsp;expression. <br/>&nbsp;* <br/>&nbsp;*&nbsp;-&nbsp;sp_identity&nbsp;was&nbsp;not&nbsp;tested&nbsp;on&nbsp;a&nbsp;64-bit&nbsp;ASE&nbsp;version. <br/>&nbsp;* <br/>&nbsp;* <br/>&nbsp;*&nbsp;Revision&nbsp;History <br/>&nbsp;*&nbsp;================ <br/>&nbsp;*&nbsp;Version&nbsp;1.0&nbsp;&nbsp;17-Dec-2000&nbsp;&nbsp;First&nbsp;version <br/>&nbsp;*&nbsp;Version&nbsp;1.1&nbsp;&nbsp;Oct-2002&nbsp;&nbsp;Handle&nbsp;identity_gap=NULL&nbsp;(thanks&nbsp;to&nbsp;Alan&nbsp;Cooper), <br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and&nbsp;some&nbsp;small&nbsp;improvements&nbsp;for&nbsp;installation <br/>&nbsp;*&nbsp;Version&nbsp;1.2&nbsp;&nbsp;Apr-2003&nbsp;&nbsp;Improved&nbsp;installation <br/>&nbsp;*&nbsp; <br/>&nbsp;* <br/>&nbsp;*&nbsp;Copyright&nbsp;Note&nbsp;&amp;&nbsp;Disclaimer&nbsp;: <br/>&nbsp;*&nbsp;============================= <br/>&nbsp;*&nbsp;This&nbsp;software&nbsp;is&nbsp;provided&nbsp;"as&nbsp;is";&nbsp;there&nbsp;is&nbsp;no&nbsp;warranty&nbsp;of&nbsp;any&nbsp;kind. <br/>&nbsp;*&nbsp;While&nbsp;this&nbsp;software&nbsp;is&nbsp;believed&nbsp;to&nbsp;work&nbsp;accurately,&nbsp;it&nbsp;may&nbsp;not&nbsp;work&nbsp; <br/>&nbsp;*&nbsp;correctly&nbsp;and/or&nbsp;reliably&nbsp;in&nbsp;a&nbsp;production&nbsp;environment.&nbsp;In&nbsp;no&nbsp;event&nbsp;shall&nbsp;&nbsp; <br/>&nbsp;*&nbsp;Rob&nbsp;Verschoor&nbsp;and/or&nbsp;Sypron&nbsp;B.V.&nbsp;be&nbsp;liable&nbsp;for&nbsp;any&nbsp;damages&nbsp;resulting&nbsp; <br/>&nbsp;*&nbsp;from&nbsp;the&nbsp;use&nbsp;of&nbsp;this&nbsp;software.&nbsp; <br/>&nbsp;*&nbsp;You&nbsp;are&nbsp;allowed&nbsp;to&nbsp;use&nbsp;this&nbsp;software&nbsp;free&nbsp;of&nbsp;charge&nbsp;for&nbsp;your&nbsp;own&nbsp; <br/>&nbsp;*&nbsp;professional,&nbsp;non-commercial&nbsp;purposes.&nbsp; <br/>&nbsp;*&nbsp;You&nbsp;are&nbsp;not&nbsp;allowed&nbsp;to&nbsp;sell&nbsp;or&nbsp;bundle&nbsp;this&nbsp;software&nbsp;or&nbsp;use&nbsp;it&nbsp;for&nbsp;any&nbsp; <br/>&nbsp;*&nbsp;other&nbsp;commercial&nbsp;purpose&nbsp;without&nbsp;prior&nbsp;written&nbsp;permission&nbsp;from&nbsp; <br/>&nbsp;*&nbsp;Rob&nbsp;Verschoor/Sypron&nbsp;B.V. <br/>&nbsp;*&nbsp;You&nbsp;may&nbsp;(re)distribute&nbsp;only&nbsp;unaltered&nbsp;copies&nbsp;of&nbsp;this&nbsp;software,&nbsp;which&nbsp; <br/>&nbsp;*&nbsp;must&nbsp;include&nbsp;this&nbsp;copyright&nbsp;note,&nbsp;as&nbsp;well&nbsp;as&nbsp;the&nbsp;copyright&nbsp;note&nbsp;in&nbsp; <br/>&nbsp;*&nbsp;the&nbsp;header&nbsp;of&nbsp;each&nbsp;stored&nbsp;procedure. <br/>&nbsp;* <br/>&nbsp;*&nbsp;Note:&nbsp;All&nbsp;trademarks&nbsp;are&nbsp;acknowledged. <br/>&nbsp;* <br/>&nbsp;*&nbsp;Please&nbsp;send&nbsp;any&nbsp;comments,&nbsp;bugs,&nbsp;suggestions&nbsp;etc.&nbsp;to&nbsp;the&nbsp;below&nbsp;email <br/>&nbsp;*&nbsp;address. <br/>&nbsp;* <br/>&nbsp;*&nbsp;Copyright&nbsp;(c)&nbsp;2000-2002&nbsp;Rob&nbsp;Verschoor/Sypron&nbsp;B.V. <br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;P.O.Box&nbsp;10695 <br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2501&nbsp;HR&nbsp;Den&nbsp;Haag <br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;Netherlands <br/>&nbsp;* <br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Email:&nbsp;rob@sypron.nl <br/>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WWW&nbsp;&nbsp;:&nbsp;http://www.sypron.nl/ <br/>&nbsp;*----------------------------------------------------------------------------&nbsp; <br/>&nbsp;*/ <br/><br/>set&nbsp;nocount&nbsp;on <br/>go <br/>set&nbsp;flushmessage&nbsp;on <br/>go <br/><br/>use&nbsp;sybsystemprocs <br/>go <br/><br/>--&nbsp;we&nbsp;need&nbsp;to&nbsp;be&nbsp;at&nbsp;ASE&nbsp;12.0&nbsp;or&nbsp;later;&nbsp;if&nbsp;not,&nbsp;abort&nbsp;this&nbsp;script <br/>if&nbsp;isnull(object_id("master.dbo.sysqueryplans"),99)&nbsp;&gt;;=&nbsp;99 <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"********************************************" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"********************************************" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;This&nbsp;script&nbsp;is&nbsp;for&nbsp;ASE&nbsp;12.0&nbsp;or&nbsp;later." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Please&nbsp;install&nbsp;SP_IDENTITY.119.SQL&nbsp;instead." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"********************************************" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"********************************************" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"" <br/>&nbsp;&nbsp;&nbsp;set&nbsp;background&nbsp;on&nbsp;&nbsp;--&nbsp;terminate&nbsp;this&nbsp;script&nbsp;now <br/>end <br/>go <br/><br/>print&nbsp;"" <br/>print&nbsp;"Installing&nbsp;'sp_identity'..." <br/>print&nbsp;"" <br/>go <br/><br/>if&nbsp;object_id("sp_identity_help")&nbsp;&lt;&gt;;&nbsp;NULL <br/>begin <br/>&nbsp;&nbsp;&nbsp;drop&nbsp;proc&nbsp;sp_identity_help <br/>end <br/>go <br/><br/>create&nbsp;proc&nbsp;sp_identity_help <br/>/*&nbsp;Copyright&nbsp;(c)&nbsp;2000-2002&nbsp;Rob&nbsp;Verschoor/Sypron&nbsp;B.V.&nbsp;*/ <br/>as <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Usage:&nbsp;sp_identity&nbsp;table_name,&nbsp;""hex-string-from-OAM-page"",&nbsp;new-identity-value&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Notes:&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;-&nbsp;specifying&nbsp;only&nbsp;parameter&nbsp;1&nbsp;retrieves&nbsp;the&nbsp;current&nbsp;identity&nbsp;value&nbsp;for" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;that&nbsp;table&nbsp;from&nbsp;the&nbsp;OAM&nbsp;page&nbsp;as&nbsp;a&nbsp;hexadecimal&nbsp;string." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;-&nbsp;specifying&nbsp;this&nbsp;hexadecimal&nbsp;string&nbsp;as&nbsp;the&nbsp;second&nbsp;parameter&nbsp;(in&nbsp;quotes)" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;will&nbsp;decode&nbsp;the&nbsp;hex&nbsp;value&nbsp;to&nbsp;a&nbsp;numeric&nbsp;value." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;-&nbsp;specifying&nbsp;a&nbsp;numeric&nbsp;value&nbsp;for&nbsp;the&nbsp;third&nbsp;parameter&nbsp;will&nbsp;set&nbsp;that" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;value&nbsp;as&nbsp;the&nbsp;new&nbsp;identity&nbsp;value&nbsp;for&nbsp;this&nbsp;table." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;-&nbsp;parameters&nbsp;2&nbsp;and&nbsp;3&nbsp;cannot&nbsp;be&nbsp;specified&nbsp;together:&nbsp;one&nbsp;of&nbsp;them&nbsp;must&nbsp;be&nbsp;NULL." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;-&nbsp;""dbcc&nbsp;traceon(3604)""&nbsp;must&nbsp;be&nbsp;run&nbsp;before&nbsp;using&nbsp;option&nbsp;2&nbsp;or&nbsp;3" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Copyright&nbsp;(c)&nbsp;2000-2002&nbsp;Rob&nbsp;Verschoor/Sypron&nbsp;B.V." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;See&nbsp;http://www.sypron.nl/idfix.html&nbsp;for&nbsp;background&nbsp;information&nbsp;&amp;&nbsp;updates." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>end <br/>go <br/><br/>grant&nbsp;execute&nbsp;on&nbsp;sp_identity_help&nbsp;to&nbsp;public <br/>dump&nbsp;tran&nbsp;sybsystemprocs&nbsp;with&nbsp;truncate_only <br/>go <br/></p>

阿辉 发表于 2006-4-14 13:23:03

<br/>if&nbsp;object_id("sp_identity")&nbsp;&lt;&gt;;&nbsp;NULL <br/>begin <br/>&nbsp;&nbsp;&nbsp;drop&nbsp;proc&nbsp;sp_identity <br/>end <br/>go <br/><br/>create&nbsp;proc&nbsp;sp_identity <br/>/*&nbsp;Copyright&nbsp;(c)&nbsp;2000-2002&nbsp;Rob&nbsp;Verschoor/Sypron&nbsp;B.V.&nbsp;*/ <br/>&nbsp;@p0&nbsp;varchar(50)&nbsp;=&nbsp;NULL,&nbsp;--&nbsp;table&nbsp;name <br/>&nbsp;@p1&nbsp;varchar(50)&nbsp;=&nbsp;NULL,&nbsp;--&nbsp;hex&nbsp;value&nbsp;to&nbsp;decode <br/>&nbsp;@p2&nbsp;numeric(38)&nbsp;=&nbsp;NULL&nbsp;&nbsp;--&nbsp;new&nbsp;value&nbsp;to&nbsp;set <br/>as <br/>begin <br/>set&nbsp;nocount&nbsp;on <br/>declare&nbsp;@n&nbsp;numeric(38),&nbsp;@j&nbsp;numeric(38),&nbsp;@n256&nbsp;numeric(3),&nbsp;@n10&nbsp;numeric(38) <br/>declare&nbsp;@i&nbsp;int,&nbsp;@max&nbsp;int,&nbsp;@idlen&nbsp;int,&nbsp;@idlenb&nbsp;int,&nbsp;@ib&nbsp;int,&nbsp;@len&nbsp;int <br/>declare&nbsp;@p0_id&nbsp;int,&nbsp;@b&nbsp;int,&nbsp;@b1&nbsp;binary(1),&nbsp;@lsb&nbsp;int <br/>declare&nbsp;@idgap&nbsp;int,&nbsp;@idburn&nbsp;int,&nbsp;@maxidgap&nbsp;numeric(38),&nbsp;@max1&nbsp;int,&nbsp;@max2&nbsp;int <br/>declare&nbsp;@idburnpct&nbsp;numeric(5,2),&nbsp;@v&nbsp;int,&nbsp;@ntab&nbsp;int <br/>declare&nbsp;@c2&nbsp;char(2),&nbsp;@doampg&nbsp;int,&nbsp;@indid&nbsp;int,&nbsp;@dbname&nbsp;varchar(32) <br/>declare&nbsp;@vc50&nbsp;varchar(50),&nbsp;@colname&nbsp;varchar(32),&nbsp;@vb16&nbsp;varbinary(16) <br/><br/>select&nbsp;@dbname&nbsp;=&nbsp;db_name() <br/><br/>--&nbsp;check&nbsp;version <br/>select&nbsp;@v&nbsp;=&nbsp;0 <br/>if&nbsp;exists&nbsp;(select&nbsp;*&nbsp;from&nbsp;sysobjects&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where&nbsp;name&nbsp;=&nbsp;"sysqueryplans"&nbsp;and&nbsp;type&nbsp;=&nbsp;"S") <br/>begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;@v&nbsp;=&nbsp;12 <br/>end <br/><br/>if&nbsp;@p0&nbsp;=&nbsp;'?' <br/>begin <br/>&nbsp;&nbsp;&nbsp;exec&nbsp;sp_identity_help <br/>&nbsp;&nbsp;&nbsp;return&nbsp;0 <br/>end <br/><br/>--&nbsp;numeric&nbsp;values <br/>select&nbsp;@n256&nbsp;=&nbsp;256 <br/>select&nbsp;@n10&nbsp;=&nbsp;10 <br/><br/>--&nbsp;id&nbsp;burning&nbsp;set&nbsp;factor <br/>select&nbsp;@idburn&nbsp;=&nbsp;value&nbsp;from&nbsp;master.dbo.syscurconfigs&nbsp;where&nbsp;config=141 <br/>select&nbsp;@idburnpct&nbsp;=&nbsp;convert(numeric(5,2),&nbsp;@idburn&nbsp;*&nbsp;0.00001) <br/><br/>--&nbsp;figure&nbsp;out&nbsp;msb/lsb <br/>select&nbsp;@lsb&nbsp;=&nbsp;0 <br/>if&nbsp;substring(convert(binary(4),&nbsp;1),&nbsp;1&nbsp;,1)&nbsp;=&nbsp;0x01&nbsp;select&nbsp;@lsb&nbsp;=&nbsp;1 <br/>if&nbsp;substring(convert(binary(4),&nbsp;1),&nbsp;2&nbsp;,1)&nbsp;=&nbsp;0x01&nbsp;select&nbsp;@lsb&nbsp;=&nbsp;2 <br/>if&nbsp;substring(convert(binary(4),&nbsp;1),&nbsp;3&nbsp;,1)&nbsp;=&nbsp;0x01&nbsp;select&nbsp;@lsb&nbsp;=&nbsp;3 <br/>if&nbsp;substring(convert(binary(4),&nbsp;1),&nbsp;4&nbsp;,1)&nbsp;=&nbsp;0x01&nbsp;select&nbsp;@lsb&nbsp;=&nbsp;4 <br/><br/>--&nbsp;get&nbsp;all&nbsp;tables&nbsp;containing&nbsp;identity&nbsp;columns&nbsp;in&nbsp;this&nbsp;database <br/>select&nbsp;id&nbsp;=&nbsp;so.id,&nbsp;owner&nbsp;=&nbsp;su.name,&nbsp;uid&nbsp;=&nbsp;so.uid,&nbsp;so.name,&nbsp;si.doampg,&nbsp;si.indid,&nbsp;idgap&nbsp;=&nbsp; <br/><br/>isnull(si.identitygap,0), <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;colname&nbsp;=&nbsp;sc.name,&nbsp;sc.prec,&nbsp;maxgap&nbsp;=&nbsp;convert(numeric(38),&nbsp;ceiling((@idburn&nbsp;*&nbsp;0.0000001)&nbsp;*&nbsp; <br/><br/>power(@n10,prec))) <br/>into&nbsp;#id <br/>from&nbsp;sysindexes&nbsp;si,&nbsp;syscolumns&nbsp;sc,&nbsp;sysobjects&nbsp;so,&nbsp;sysusers&nbsp;su <br/>where&nbsp;si.indid&nbsp;&lt;&nbsp;2&nbsp; <br/>&nbsp;&nbsp;and&nbsp;so.type&nbsp;=&nbsp;"U"&nbsp; <br/>&nbsp;&nbsp;and&nbsp;sc.status&nbsp;&amp;&nbsp;128&nbsp;=&nbsp;128 <br/>&nbsp;&nbsp;and&nbsp;so.id&nbsp;=&nbsp;sc.id&nbsp; <br/>&nbsp;&nbsp;and&nbsp;so.id&nbsp;=&nbsp;si.id <br/>&nbsp;&nbsp;and&nbsp;so.uid&nbsp;=&nbsp;su.uid <br/>select&nbsp;@ntab&nbsp;=&nbsp;@@rowcount <br/><br/>set&nbsp;arithabort&nbsp;numeric_truncation&nbsp;off <br/><br/>if&nbsp;@p0&nbsp;=&nbsp;null <br/>begin <br/>&nbsp;&nbsp;&nbsp;--&nbsp;display&nbsp;all&nbsp;tables&nbsp;with&nbsp;identity&nbsp;columns&nbsp;in&nbsp;the&nbsp;current&nbsp;DB <br/>&nbsp;&nbsp;&nbsp;if&nbsp;@ntab&nbsp;=&nbsp;0 <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;There&nbsp;are&nbsp;no&nbsp;tables&nbsp;with&nbsp;an&nbsp;identity&nbsp;column&nbsp;in&nbsp;database&nbsp;'%1!'",&nbsp;@dbname <br/>&nbsp;&nbsp;return&nbsp;0 <br/>&nbsp;&nbsp;&nbsp;end <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Tables&nbsp;with&nbsp;an&nbsp;identity&nbsp;column&nbsp;in&nbsp;database&nbsp;'%1!':",&nbsp;@dbname <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@max1&nbsp;=&nbsp;max(char_length(owner&nbsp;+&nbsp;"."&nbsp;+&nbsp;name&nbsp;+&nbsp;"."&nbsp;+&nbsp;colname))&nbsp;+&nbsp;12&nbsp;from&nbsp;#id <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@max2&nbsp;=&nbsp;max(char_length(convert(varchar(38),&nbsp;maxgap)))&nbsp;+&nbsp;7&nbsp;from&nbsp;#id <br/><br/>&nbsp;&nbsp;&nbsp;if&nbsp;@max1&nbsp;&lt;=&nbsp;52&nbsp;and&nbsp;@max2&nbsp;&lt;=&nbsp;24 <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;convert(varchar(52),&nbsp;owner&nbsp;+&nbsp;"."&nbsp;+&nbsp;name&nbsp;+&nbsp;"."&nbsp;+&nbsp;colname&nbsp;+&nbsp;"&nbsp;numeric("&nbsp;+&nbsp; <br/><br/>convert(varchar(2),prec)&nbsp;+&nbsp;")")&nbsp;"Owner.Table.Column&nbsp;datatype", <br/>&nbsp;&nbsp;&nbsp;&nbsp;convert(varchar(24),&nbsp;case&nbsp;when&nbsp;idgap&nbsp;=&nbsp;0&nbsp;then&nbsp;convert(varchar(38),maxgap)&nbsp;+&nbsp;"&nbsp; <br/><br/>(burn)" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;convert(varchar,&nbsp;idgap)&nbsp;+&nbsp;"&nbsp;(identity_gap)" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end)&nbsp;"Maximum&nbsp;Identity&nbsp;Gap" <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;#id <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order&nbsp;by&nbsp;name <br/>&nbsp;&nbsp;&nbsp;end <br/>&nbsp;&nbsp;&nbsp;else <br/>&nbsp;&nbsp;&nbsp;if&nbsp;@max1&nbsp;&lt;=&nbsp;32&nbsp;and&nbsp;@max2&nbsp;&lt;=&nbsp;44 <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;convert(varchar(32),&nbsp;owner&nbsp;+&nbsp;"."&nbsp;+&nbsp;name&nbsp;+&nbsp;"."&nbsp;+&nbsp;colname&nbsp;+&nbsp;"&nbsp;numeric("&nbsp;+&nbsp; <br/><br/>convert(varchar(2),prec)&nbsp;+&nbsp;")")&nbsp;"Owner.Table.Column&nbsp;datatype", <br/>&nbsp;&nbsp;&nbsp;&nbsp;convert(varchar(44),&nbsp;case&nbsp;when&nbsp;idgap&nbsp;=&nbsp;0&nbsp;then&nbsp;convert(varchar(38),maxgap)&nbsp;+&nbsp;"&nbsp; <br/><br/>(burn)" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;convert(varchar,&nbsp;idgap)&nbsp;+&nbsp;"&nbsp;(identity_gap)" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end)&nbsp;"Maximum&nbsp;Identity&nbsp;Gap" <br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;#id <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order&nbsp;by&nbsp;name <br/>&nbsp;&nbsp;&nbsp;end <br/>&nbsp;&nbsp;&nbsp;else <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;convert(varchar(78),&nbsp;owner&nbsp;+&nbsp;"."&nbsp;+&nbsp;name&nbsp;+&nbsp;"."&nbsp;+&nbsp;colname&nbsp;+&nbsp;"&nbsp;numeric("&nbsp;+&nbsp; <br/><br/>convert(varchar(2),prec)&nbsp;+&nbsp;")")&nbsp;"Owner.Table.Column&nbsp;datatype", <br/>&nbsp;&nbsp;&nbsp;&nbsp;convert(varchar(50),&nbsp;case&nbsp;when&nbsp;idgap&nbsp;=&nbsp;0&nbsp;then&nbsp;convert(varchar(38),maxgap)&nbsp;+&nbsp;"&nbsp; <br/><br/>(burn)" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;convert(varchar,&nbsp;idgap)&nbsp;+&nbsp;"&nbsp;(identity_gap)" <br/>&nbsp;&nbsp;end)&nbsp;"Maximum&nbsp;Identity&nbsp;Gap" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;#id <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order&nbsp;by&nbsp;name <br/>&nbsp;&nbsp;&nbsp;end <br/><br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Legend:" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;(burn)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;gap&nbsp;size&nbsp;is&nbsp;determined&nbsp;by&nbsp;""identity&nbsp;burning&nbsp;set&nbsp;factor""&nbsp;" <br/>&nbsp;&nbsp;&nbsp;if&nbsp;@v&nbsp;=&nbsp;12 <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;(identity_gap)&nbsp;:&nbsp;gap&nbsp;size&nbsp;is&nbsp;determined&nbsp;by&nbsp;the&nbsp;""identity_gap""&nbsp;setting" <br/>&nbsp;&nbsp;&nbsp;end <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Current&nbsp;value&nbsp;for&nbsp;""identity&nbsp;burning&nbsp;set&nbsp;factor""&nbsp;=&nbsp;%1!&nbsp;(=%2!%%)",&nbsp;@idburn,&nbsp;@idburnpct <br/><br/><br/>&nbsp;&nbsp;&nbsp;return&nbsp;0 <br/>end <br/><br/>if&nbsp;charindex("sa_role",&nbsp;show_role())&nbsp;=&nbsp;0 <br/>begin&nbsp; <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"You&nbsp;must&nbsp;have&nbsp;'sa_role'&nbsp;to&nbsp;run&nbsp;this&nbsp;procedure." <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>if&nbsp;charindex("sybase_ts_role",&nbsp;show_role())&nbsp;=&nbsp;0 <br/>begin&nbsp; <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"You&nbsp;must&nbsp;have&nbsp;'sybase_ts_role'&nbsp;to&nbsp;run&nbsp;this&nbsp;procedure." <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>--&nbsp;get&nbsp;some&nbsp;info&nbsp;on&nbsp;the&nbsp;object <br/>select&nbsp;@p0_id&nbsp;=&nbsp;object_id(@p0) <br/>if&nbsp;@p0_id&nbsp;=&nbsp;NULL <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;'%1!'&nbsp;is&nbsp;not&nbsp;a&nbsp;user&nbsp;table.",&nbsp;@p0 <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>if&nbsp;@p0&nbsp;not&nbsp;like&nbsp;"%.%" <br/>begin <br/>&nbsp;&nbsp;select&nbsp;@ntab&nbsp;=&nbsp;count(*)&nbsp;from&nbsp;sysobjects&nbsp;where&nbsp;name&nbsp;=&nbsp;@p0&nbsp;and&nbsp;type&nbsp;=&nbsp;"U" <br/><br/>&nbsp;&nbsp;if&nbsp;@ntab&nbsp;&gt;;&nbsp;1 <br/>&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;%1!&nbsp;tables&nbsp;named&nbsp;'%2!'&nbsp;exist&nbsp;in&nbsp;this&nbsp;database:",&nbsp;@ntab,&nbsp;@p0 <br/>&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;owner&nbsp;+&nbsp;"."&nbsp;+&nbsp;name&nbsp;"owner.table_name"&nbsp; <br/>&nbsp;from&nbsp;#id&nbsp;where&nbsp;name&nbsp;=&nbsp;@p0&nbsp;order&nbsp;by&nbsp;uid <br/>&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Specify&nbsp;'owner.table_name'&nbsp;to&nbsp;identify&nbsp;the&nbsp;table." <br/>&nbsp;return&nbsp;-1 <br/>&nbsp;&nbsp;end <br/>end <br/><br/>select&nbsp;@doampg&nbsp;=&nbsp;doampg,&nbsp;@indid&nbsp;=&nbsp;indid,&nbsp;@idgap&nbsp;=&nbsp;idgap <br/>from&nbsp;#id&nbsp;where&nbsp;id&nbsp;=&nbsp;@p0_id <br/><br/>if&nbsp;not&nbsp;exists&nbsp;(select&nbsp;1&nbsp;from&nbsp;syscolumns&nbsp;where&nbsp;id&nbsp;=&nbsp;@p0_id&nbsp;and&nbsp;status&nbsp;&amp;&nbsp;128&nbsp;=&nbsp;128)&nbsp;&nbsp; <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;Table&nbsp;'%1!'&nbsp;does&nbsp;not&nbsp;have&nbsp;an&nbsp;identity&nbsp;column",&nbsp;@p0 <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>--&nbsp;retrieve&nbsp;the&nbsp;length&nbsp;of&nbsp;the&nbsp;numeric&nbsp;identity&nbsp;column&nbsp;as&nbsp;declared&nbsp;when&nbsp;the <br/>--&nbsp;table&nbsp;was&nbsp;created <br/>select&nbsp;@len&nbsp;=&nbsp;prec,&nbsp;@colname&nbsp;=&nbsp;name <br/>from&nbsp;syscolumns&nbsp;where&nbsp;id&nbsp;=&nbsp;@p0_id&nbsp;and&nbsp;status&nbsp;&amp;&nbsp;128&nbsp;=&nbsp;128 <br/>if&nbsp;@@rowcount&nbsp;=&nbsp;0 <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;Could&nbsp;not&nbsp;retrieve&nbsp;length&nbsp;of&nbsp;identity&nbsp;column&nbsp;for&nbsp;table&nbsp;'%1!'",&nbsp;@p0 <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>select&nbsp;@idlen&nbsp;=&nbsp;@len&nbsp;--&nbsp;column&nbsp;precision&nbsp;(positions) <br/>select&nbsp;@idlenb&nbsp;=&nbsp;(@idlen+1-((@idlen+5)/12)-(@idlen/12))/2&nbsp;--&nbsp;column&nbsp;length&nbsp;(bytes) <br/>

阿辉 发表于 2006-4-14 13:23:24

<br/>print&nbsp;"&nbsp;" <br/>print&nbsp;"&nbsp;Table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;%1!&nbsp;(id=%2!)",&nbsp;@p0,&nbsp;@p0_id <br/>print&nbsp;"&nbsp;Identity&nbsp;column&nbsp;&nbsp;&nbsp;=&nbsp;%1!&nbsp;numeric(%2!)",&nbsp;@colname,&nbsp;@len <br/>--print&nbsp;"&nbsp;OAM&nbsp;page&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;%1!",&nbsp;@doampg <br/>--print&nbsp;"&nbsp;Bytes&nbsp;on&nbsp;OAM&nbsp;page&nbsp;=&nbsp;%1!",&nbsp;@idlenb <br/>if&nbsp;@idgap&nbsp;&gt;;&nbsp;0 <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Max.&nbsp;Identity&nbsp;Gap&nbsp;=&nbsp;%1!&nbsp;(""identity_gap""&nbsp;=&nbsp;%2!)",&nbsp;@idgap,&nbsp;@idgap <br/>end <br/>else <br/>begin <br/>&nbsp;&nbsp;&nbsp;set&nbsp;arithabort&nbsp;numeric_truncation&nbsp;off <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@maxidgap&nbsp;=&nbsp;ceiling((convert(numeric(38),@idburn)&nbsp;*&nbsp;0.0000001)&nbsp;*&nbsp;power(@n10,@len)) <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Max.&nbsp;Identity&nbsp;Gap&nbsp;=&nbsp;%1!",&nbsp;@maxidgap <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(""identity&nbsp;burning&nbsp;set&nbsp;factor""&nbsp;=&nbsp;%1!&nbsp;=&nbsp;%2!%%)",&nbsp;@idburn,&nbsp;@idburnpct <br/>&nbsp;&nbsp;&nbsp;if&nbsp;@v&nbsp;=&nbsp;12 <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Note:&nbsp;""identity_gap""&nbsp;has&nbsp;not&nbsp;been&nbsp;set&nbsp;for&nbsp;this&nbsp;table&nbsp;!)"&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;end <br/>end <br/>print&nbsp;"&nbsp;" <br/><br/>if&nbsp;@p1&nbsp;=&nbsp;NULL&nbsp;and&nbsp;@p2&nbsp;=&nbsp;NULL&nbsp;--&nbsp;retrieve&nbsp;current&nbsp;ID&nbsp;value <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Reading&nbsp;identity&nbsp;value&nbsp;from&nbsp;OAM&nbsp;page...&nbsp;(traceflag&nbsp;3604&nbsp;should&nbsp;be&nbsp;enabled&nbsp;!)" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;dbcc&nbsp;object_atts&nbsp;(@p0,&nbsp;0,&nbsp;get) <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;To&nbsp;decode&nbsp;this&nbsp;hexadecimal&nbsp;value,&nbsp;re-run&nbsp;'sp_identity'&nbsp;with&nbsp;the&nbsp;hexadecimal" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;string&nbsp;as&nbsp;a&nbsp;quoted&nbsp;2nd&nbsp;parameter&nbsp;(you&nbsp;can&nbsp;leave&nbsp;the&nbsp;spaces&nbsp;in).&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Example:&nbsp;&nbsp;sp_identity&nbsp;%1!,&nbsp;""the-hex-string-from-the-above-output""&nbsp;",&nbsp;@p0 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;-- <br/>&nbsp;&nbsp;&nbsp;--&nbsp;only&nbsp;for&nbsp;12.0+,&nbsp;dbcc&nbsp;listoam&nbsp;will&nbsp;display&nbsp;the&nbsp;values&nbsp;in&nbsp;the&nbsp;OAM&nbsp;and&nbsp;the&nbsp;DES <br/>&nbsp;&nbsp;&nbsp;-- <br/>&nbsp;&nbsp;&nbsp;--dbcc&nbsp;listoam(@dbname,&nbsp;@p0_id,&nbsp;@indid) <br/>&nbsp;&nbsp;&nbsp;-- <br/>&nbsp;&nbsp;&nbsp;return&nbsp;0 <br/>end <br/><br/>if&nbsp;upper(@p1)&nbsp;like&nbsp;"[&nbsp;0-9A-F]%"&nbsp;--&nbsp;entered&nbsp;a&nbsp;hex&nbsp;string,&nbsp;decode&nbsp;it <br/>begin <br/><br/>if&nbsp;@p2&nbsp;!=&nbsp;NULL <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;When&nbsp;decoding&nbsp;a&nbsp;hex&nbsp;value&nbsp;from&nbsp;the&nbsp;OAM&nbsp;page,&nbsp;parameter&nbsp;3" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;(the&nbsp;new&nbsp;identity&nbsp;value)&nbsp;must&nbsp;be&nbsp;NULL." <br/>&nbsp;&nbsp;&nbsp;exec&nbsp;sp_identity_help <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>select&nbsp;@ib&nbsp;=&nbsp;@idlenb&nbsp;--&nbsp;counts&nbsp;bytes <br/>select&nbsp;@i&nbsp;&nbsp;=&nbsp;char_length(@p1)&nbsp;--&nbsp;counts&nbsp;string <br/>select&nbsp;@n&nbsp;=&nbsp;0&nbsp;--&nbsp;holds&nbsp;result <br/><br/>while&nbsp;1&nbsp;=&nbsp;1 <br/>begin <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@c2&nbsp;=&nbsp;substring(@p1,&nbsp;(char_length(@p1)-@i)+1,&nbsp;2) <br/><br/>&nbsp;&nbsp;&nbsp;--print&nbsp;"Step&nbsp;%1!,&nbsp;[%2!]",&nbsp;@ib,&nbsp;@c2 <br/>&nbsp;&nbsp;&nbsp;if&nbsp;upper(substring(@c2,1,1))&nbsp;=&nbsp;"&nbsp;"&nbsp;--&nbsp;ignore&nbsp;single&nbsp;space&nbsp;pasted&nbsp;in&nbsp;by&nbsp;user <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;@i&nbsp;=&nbsp;@i&nbsp;-&nbsp;1 <br/>&nbsp;continue <br/>&nbsp;&nbsp;&nbsp;end <br/><br/>&nbsp;&nbsp;&nbsp;if&nbsp;(upper(@c2)&nbsp;not&nbsp;like&nbsp;"")&nbsp; <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;Invalid&nbsp;characters&nbsp;(%1!)&nbsp;in&nbsp;hex&nbsp;string",&nbsp;@c2 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break <br/>&nbsp;&nbsp;&nbsp;end <br/><br/>&nbsp;&nbsp;&nbsp;--&nbsp;add&nbsp;this&nbsp;byte&nbsp;to&nbsp;the&nbsp;result <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@vc50&nbsp;=&nbsp;@vc50&nbsp;+&nbsp;@c2 <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@j&nbsp;=&nbsp;power(@n256,&nbsp;(@ib-1)) <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@n&nbsp;=&nbsp;@n&nbsp;+&nbsp;@j&nbsp;*&nbsp;hextoint("0x"&nbsp;+&nbsp;@c2) <br/>&nbsp;&nbsp;&nbsp;--print&nbsp;"Step&nbsp;%1!,&nbsp;exp=&nbsp;%2!,&nbsp;result&nbsp;=&nbsp;%3!",&nbsp;@ib,&nbsp;@j,&nbsp;@n <br/><br/>&nbsp;&nbsp;&nbsp;--&nbsp;next&nbsp;byte <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@ib&nbsp;=&nbsp;@ib&nbsp;-&nbsp;1&nbsp; <br/>&nbsp;&nbsp;&nbsp;if&nbsp;@ib&nbsp;=&nbsp;0&nbsp;break&nbsp;&nbsp;--&nbsp;ready <br/><br/>&nbsp;&nbsp;&nbsp;--&nbsp;next&nbsp;2&nbsp;chars <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@i&nbsp;=&nbsp;@i&nbsp;-&nbsp;2 <br/>&nbsp;&nbsp;&nbsp;if&nbsp;@i&nbsp;=&nbsp;0&nbsp; <br/>&nbsp;&nbsp;&nbsp;begin <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&nbsp;we&nbsp;shouldn't&nbsp;have&nbsp;got&nbsp;here,&nbsp;error <br/>&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;ID&nbsp;column&nbsp;length&nbsp;and&nbsp;specified&nbsp;hex&nbsp;string&nbsp;do&nbsp;not&nbsp;match&nbsp;!" <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break <br/>&nbsp;&nbsp;&nbsp;end <br/>end <br/><br/>if&nbsp;@ib&nbsp;=&nbsp;0 <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Decoded&nbsp;identity&nbsp;value&nbsp;on&nbsp;OAM&nbsp;page&nbsp;=&nbsp;%1!",&nbsp;@n <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;(hex=&nbsp;%1!)",&nbsp;@vc50 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;return&nbsp;0 <br/>end <br/>else <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;Aborted&nbsp;due&nbsp;to&nbsp;error." <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/>end <br/><br/>if&nbsp;@p2&nbsp;!=&nbsp;NULL&nbsp;--&nbsp;entered&nbsp;a&nbsp;new&nbsp;ID&nbsp;value,&nbsp;set&nbsp;it <br/>begin <br/><br/>if&nbsp;@p1&nbsp;!=&nbsp;NULL <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;When&nbsp;setting&nbsp;a&nbsp;new&nbsp;identity&nbsp;value,&nbsp;parameter&nbsp;2" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;(the&nbsp;hex&nbsp;string&nbsp;from&nbsp;the&nbsp;OAM&nbsp;page)&nbsp;must&nbsp;be&nbsp;NULL." <br/>&nbsp;&nbsp;&nbsp;exec&nbsp;sp_identity_help <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>--&nbsp;set&nbsp;the&nbsp;new&nbsp;ID&nbsp;value <br/>if&nbsp;@p2&nbsp;&lt;=&nbsp;0 <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;The&nbsp;new&nbsp;identity&nbsp;value&nbsp;must&nbsp;be&nbsp;&gt;;=&nbsp;0." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;exec&nbsp;sp_identity_help <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>if&nbsp;char_length(convert(varchar,&nbsp;@p2))&nbsp;&gt;;&nbsp;@idlen <br/>begin <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@vc50&nbsp;=&nbsp;replicate("9",&nbsp;@idlen) <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;New&nbsp;identity&nbsp;value&nbsp;(%1!)&nbsp;is&nbsp;too&nbsp;large",&nbsp;@p2 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;this&nbsp;identity&nbsp;column.&nbsp;The&nbsp;maximum&nbsp;possible&nbsp;value",&nbsp;@p2 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is&nbsp;%1!&nbsp;(%2!&nbsp;positions).",&nbsp;@vc50,&nbsp;@idlen <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>if&nbsp;@lsb&nbsp;=&nbsp;0 <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"Internal&nbsp;error&nbsp;in&nbsp;'sp_identity':" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"Cannot&nbsp;figure&nbsp;out&nbsp;byte&nbsp;order&nbsp;on&nbsp;this&nbsp;platform." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"Please&nbsp;send&nbsp;a&nbsp;note&nbsp;to&nbsp;'rob@sypron.nl'&nbsp;with&nbsp;the&nbsp;text&nbsp;of&nbsp;this" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"error&nbsp;and&nbsp;your&nbsp;@@version&nbsp;string." <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/><br/>--&nbsp;convert&nbsp;the&nbsp;numeric&nbsp;value&nbsp;to&nbsp;hex <br/>select&nbsp;@ib&nbsp;=&nbsp;@idlenb&nbsp;--&nbsp;counts&nbsp;bytes <br/>select&nbsp;@i&nbsp;&nbsp;=&nbsp;15 <br/><br/>select&nbsp;@vc50&nbsp;=&nbsp;NULL&nbsp;--&nbsp;holds&nbsp;result <br/>select&nbsp;@vb16&nbsp;=&nbsp;NULL&nbsp;--&nbsp;holds&nbsp;result <br/>select&nbsp;@n256&nbsp;=&nbsp;256 <br/>select&nbsp;@n&nbsp;=&nbsp;@p2 <br/>set&nbsp;arithabort&nbsp;numeric_truncation&nbsp;off <br/><br/>while&nbsp;1&nbsp;=&nbsp;1 <br/>begin <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@j&nbsp;=&nbsp;power(@n256,&nbsp;@i) <br/><br/>&nbsp;&nbsp;&nbsp;select&nbsp;@b&nbsp;=&nbsp;@n&nbsp;/&nbsp;@j <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@n&nbsp;=&nbsp;@n&nbsp;-&nbsp;(@b&nbsp;*&nbsp;@j) <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@c2&nbsp;=&nbsp;right(inttohex(@b),2) <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@b1&nbsp;=&nbsp;substring(convert(binary(4),&nbsp;@b),&nbsp;@lsb,1) <br/><br/>&nbsp;&nbsp;&nbsp;select&nbsp;@vb16&nbsp;=&nbsp;@vb16&nbsp;+&nbsp;@b1 <br/><br/>&nbsp;&nbsp;&nbsp;--print&nbsp;"Step&nbsp;%1!,&nbsp;@b=%2!,&nbsp;hex(c2)=%3!,&nbsp;hex(b1)=%5!,&nbsp;result=%4!",&nbsp;@i,&nbsp;@b,&nbsp;@c2,&nbsp;@vb16,&nbsp;@b1 <br/><br/>&nbsp;&nbsp;&nbsp;select&nbsp;@i&nbsp;=&nbsp;@i&nbsp;-&nbsp;1&nbsp; <br/>&nbsp;&nbsp;&nbsp;if&nbsp;@i&nbsp;&lt;&nbsp;0&nbsp;break&nbsp;&nbsp;--&nbsp;ready <br/>end <br/><br/>if&nbsp;@i&nbsp;&lt;&nbsp;0 <br/>begin <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@vb16&nbsp;=&nbsp;substring(@vb16,&nbsp;16&nbsp;-&nbsp;(@idlenb)&nbsp;+&nbsp;1,&nbsp;(@idlenb)&nbsp;)&nbsp;+&nbsp;substring(@vb16,&nbsp;1,&nbsp;16&nbsp;-&nbsp; <br/><br/>(@idlenb)&nbsp;) <br/><br/>&nbsp;&nbsp;&nbsp;--&nbsp;set&nbsp;the&nbsp;new&nbsp;ID&nbsp;value <br/>&nbsp;&nbsp;&nbsp;dbcc&nbsp;object_atts(@p0,&nbsp;0,&nbsp;"put",&nbsp;@vb16) <br/><br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Identity&nbsp;value&nbsp;on&nbsp;OAM&nbsp;page&nbsp;has&nbsp;been&nbsp;set&nbsp;to&nbsp;%1!",&nbsp;@p2 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;(hex=&nbsp;%1!)",&nbsp;@vb16 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;select&nbsp;@p2&nbsp;=&nbsp;@p2&nbsp;+&nbsp;1 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;You&nbsp;should&nbsp;now&nbsp;do&nbsp;a&nbsp;'shutdown&nbsp;with&nbsp;nowait'&nbsp;immediately." <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;After&nbsp;restarting&nbsp;the&nbsp;server,&nbsp;the&nbsp;value&nbsp;assigned&nbsp;to&nbsp;the&nbsp;next&nbsp;row&nbsp;" <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;inserted&nbsp;into&nbsp;'%1!'&nbsp;will&nbsp;be&nbsp;%2!.",&nbsp;@p0,&nbsp;@p2 <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;" <br/>&nbsp;&nbsp;&nbsp;return&nbsp;0 <br/>end <br/>else <br/>begin <br/>&nbsp;&nbsp;&nbsp;print&nbsp;"&nbsp;Error:&nbsp;Aborted&nbsp;due&nbsp;to&nbsp;error." <br/>&nbsp;&nbsp;&nbsp;return&nbsp;-1 <br/>end <br/>&nbsp;&nbsp;&nbsp; <br/>end <br/><br/>--&nbsp;we&nbsp;should&nbsp;never&nbsp;get&nbsp;here <br/>print&nbsp;"Internal&nbsp;error&nbsp;in&nbsp;'sp_identity':&nbsp;Reached&nbsp;invalid&nbsp;end&nbsp;of&nbsp;procedure." <br/>return&nbsp;-1 <br/>end <br/>go <br/><br/>grant&nbsp;execute&nbsp;on&nbsp;sp_identity&nbsp;to&nbsp;public <br/>dump&nbsp;tran&nbsp;sybsystemprocs&nbsp;with&nbsp;truncate_only <br/>go <br/><br/><br/>print&nbsp;"Ready.&nbsp;For&nbsp;usage&nbsp;information,&nbsp;run&nbsp;'sp_identity&nbsp;""?""&nbsp;'." <br/>print&nbsp;"" <br/>go <br/><br/>/* <br/>**&nbsp;end <br/>*/<br/>

75217521 发表于 2006-11-11 11:42:05

有谁用过吗,给提点意见或建议,使用这个存储过程安全吗?!
页: [1]
查看完整版本: [转帖]修复identity 类型字段数据的跳跃(译)

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com