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
ng you need to run a demo of how

* to use a two-table database design technique that allows

* identity gaps to be fixed quickly using a stored procedure.


* This script set up the following objects:

*

* - a table 'invoices', holding application data

* - a table 'invoices_keytable', for generating invoice numbers

* - a procedure 'sp_fix_idgap_invoices' to repair identity gaps

* in the 'invoices' table

* - a procedure 'sp_insert_invoice' to simulate the application

* inserting invoices

*

/

if not exists(select * from master.dbo.sysdatabases

where name = "my_db")

begin

print "***************************************************"

print "*** You should edit this script first ! ***"

print "*** Change 'my_db' to the name of your database ***"

print "*** in which you want to run this script. ***"

print "***************************************************"

end

go

use my_db

go

/*

* create the application table holding invoice data

*/

if object_id("invoices") != NULL

begin

drop table invoices

end

go

create table invoices

(invoice_nr numeric(10,0),

customer_nr int,

amount money)

go

create unique index ix1 on invoices(invoice_nr)

go

grant all on invoices to public

go

/*

* Create a separate procedure for creating the keytable.

* This is required because it's not allowed to drop

* and recreate an object with the same name in one procedure


*/

if object_id("invoices_keytable") != NULL

begin

drop table invoices_keytable

end

go

if object_id("sp_create_invoices_keytable") != NULL

begin

drop procedure sp_create_invoices_keytable

end

go

create procedure sp_create_invoices_keytable

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

as

begin

create table invoices_keytable

(dummy_key numeric(10,0) identity)

/*

* Partitioning only works in system 11.0 and later

* The number of partitions can be increased if there

* will be many concurrent inserts.

*/

alter table invoices_keytable partition 10

end

go

grant execute on sp_create_invoices_keytable to public

go

/*

* create the keytable

*/

exec sp_create_invoices_keytable

go

/*

* create a procedure to simulate application activity:

* first generate a new invoice number, then insert a new invoice

*/

if object_id("sp_insert_invoice") != NULL

begin

drop procedure sp_insert_invoice

end

go

create procedure sp_insert_invoice

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

@p_customer_nr int,

@p_amount money

as

begin

insert invoices_keytable values ()

insert invoices values (@@identity, @p_customer_nr, @p_amount)


end

go

grant execute on sp_insert_invoice to public

go

/*

* Create the procedure to fix an identity gap.

* It takes one parameter, and can be called in two ways:

*

* 1. If "-1" is specified as a parameter, the keytable

* will be dropped and recreated according to the highest

* existing invoice number. The best use of this form

* is to always run this procedure directly after server

* startup, so that a possible identity gap is be corrected

* before new invoices are inserted which could cause problems.

*

* 2. If another value is specified, it must be invoice number

* generated just before the identity gap occurred. All invoices

* having a higher invoice numbers than this will be corrected

* downwards to create a consecutive range. The keytable will

* be recreated and adjusted accordingly.

* Example: suppose the following invoice numbers exist:

* (...)

* 10028

* 10029

* 10030

* 10031 <--\

* 5000002 <--- identity gap here

* 5000003

*

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

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

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