e股脑电脑教程网
  • 首 页
  • 操作系统
  • 应用软件
  • 下载工具
  • 影音视频
  • 办公软件
  • 媒体制作
  • 网站建设
  • 平面设计
  • 数据库
  • 程序开发
  • 视频教程
编辑推荐: | 文章搜索:
您现在的位置: e股脑 >> 数据库 >> Sybase教程 >> Dealing with identity gaps (Freebob) >> 教程正文
 
教程搜索
 
 
相关教程
  • Sybase数据库简介
  • 为什么有时候数据库事务日志满了,不能
  • 在LINUX下安装 Sybase ASE 11.0.3.3
  • Dealing with identity gaps (Freebo
  • 关于sybase数据库的锁
  • SYBASE内存和缓冲区管理(rekcah0)
  • sybase 临时数据库tempdb (Arnold)
  • SYBASE dbccdb的安装配置攻略
  • 从数据库应用系统查找解决阻塞问题
  • Sybase数据库的碎片整理( arnold )
  • SYBASE数据库用户管理基本概念 (howto
  • sybase 珍藏系列之三(from shanhan)
  • sybase 珍藏系列之四(from shanhan)
  • SYBASE补丁安装指南
  • 解决 Error 605 错误的方案
  • Sybase TraceFlag 定义
 
 

图文教程


  • Windows抢了谁的饭碗 非主流操作系统To

  • 地球还是火星 平常心看“非主流”

  • 综合运用Office 2007批量制作奖状

  • 没有系统盘如何才能修复受损系统?

  • 巧妙运用Excel中边界的附加功能!
 
 
赞 助 商
 
 
Dealing with identity gaps (Freebob)
  • 来源:e股脑
  • 点击次数:
  • 更新时间:2007-8-9
>* Now run "exec sp_fix_idgap_invoices 10031", and the last two

* invoices will be corrected. Also, the next invoice will

* receive number 10034.

*/

if object_id("sp_fix_idgap_invoices") != NULL

begin

drop procedure sp_fix_idgap_invoices

end

go

create procedure sp_fix_idgap_invoices


/* Copyright (c) 1998 Rob Verschoor/Sypron B.V. */

@p_gap_low numeric(10,0)

as

begin

declare @gap_low numeric(10,0)

declare @gap_low_plus_1 numeric(10,0)

declare @gap_high numeric(10,0)

declare @gap_size numeric(10,0)

declare @gap_max numeric(10,0)

declare @set_new_idval numeric(10,0)

declare @rows int

declare @error int

if (@p_gap_low != -1) and (@p_gap_low < 1)

begin

print "Invalid invoice number specified."

print "You must specify the last correct invoice number before the identity gap."

return (-1)

end

/*

* First check identity_insert is not active for any

* other table: there can be only one at a time

* if another table is already in this mode, the

* procedure will be aborted here and user must switch off

* identity_insert on that other table before continuing.

*/

set identity_insert invoices_keytable on

set identity_insert invoices_keytable off

if @p_gap_low > 0

begin

/*

* check the row at lower end of gap exists

*/

select @gap_low = invoice_nr

from invoices

where invoice_nr = @p_gap_low

select @error = @@error, @rows = @@rowcount

if @error != 0

begin

print "Error occurred"

return (-1)

end

if @rows = 0

begin


print "Could not find invoice number specified."

print "You must specify the last correct invoice number before the identity gap."

return (-1)

end

select @gap_low_plus_1 = @gap_low + 1

/*

* determine the size of the identity gap

*/

select @gap_high = min(invoice_nr)

from invoices

where invoice_nr > @gap_low

if @@rowcount = 0 or @@error != 0

begin

print "Row at upper end not found or error occurred"

return (-1)

end

/*

* calculate size of gap; must be > 99 to be

* considered a real identity gap(this is

* an arbitrary limit). Small 'gaplets' of

* non-existing numbers can always exists due to

* rolled-back transactions

*/

select @gap_size = @gap_high - @gap_low

if @gap_size < 100

begin

print "This is not a real identity gap"

return (-1)

end

end /* if @p_gap_low > 0 */

/*

* determine the highest existing key value

*/

select @gap_max = max(invoice_nr)

from invoices

if @@rowcount = 0 or @@error != 0

begin

print "Error occurred"

return (-1)

end

/*

* calculate new value for identity column in key table

*/

if @p_gap_low > 0

begin

/*

* now update the application table to correct


* the undesirable high key values

*/

update invoices

set invoice_nr = invoice_nr - @gap_size + 1

where invoice_nr > @gap_low

select @error = @@error, @rows = @@rowcount

if @error != 0 or @rows = 0

begin

print "No rows updated or error occurred"

return (-1)

end

/*

* tell user what happened

*/

print "%1! invoice numbers have been corrected.", @rows

print "Invoice numbers starting from %1! have been reset to %2! and further.",

@gap_high, @gap_low_plus_1

/*

* value to reset keytable with

*/

select @set_new_idval = @gap_max - @gap_size + 1

end

else

begin

/*

* case where keytable will be reset anyway

*/

select @set_new_idval = @gap_max

end

/*

* drop existing keytable; note that it's not necessary to

* unpartition th

上一页  1 2 3 4 5 6 7 下一页
  • 上一篇教程: 关于sybase数据库的锁
  • 下一篇教程: 在LINUX下安装 Sybase ASE 11.0.3.3
  •  

    关于本站 | 广告联系 | 版权声明 | 使用帮助

    Copyright © 2004-2008 www.egunao.com All rights reserved.