sqlserver数据库最大Id冲突问题解决方法之一

前端之家收集整理的这篇文章主要介绍了sqlserver数据库最大Id冲突问题解决方法之一前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="18536" class="copybut" id="copybut18536" onclick="doCopy('code18536')"> 代码如下:

<div class="codebody" id="code18536">
CREATE TABLE [dbo].[TbGuidTable](
[TableName] varchar NOT NULL,
[KeyName] varchar NOT NULL,
[KeyValue] varchar NOT NULL
) ON [PRIMARY] GO if exists (select from dbo.sysobjects where id = object_id(N'PCreateGuid') and OBJECTPROPERTY(id,N'IsProcedure') = 1)
drop procedure PCreateGuid
GO
------------------------------------
--用途:增加一条记录 个人信息
--项目名称
--说明:
--时间:2011-7-4 15:34:12,2011-08-15
------------------------------------
CREATE PROCEDURE PCreateGuid
@tableName varchar(50),
@keyname varchar(100),
@guid varchar(100) out
as
if not exists(select
from TbGuidTable where tablename=@tableName and keyname=@keyname)
insert into TbGuidTable (tablename,keyname,keyvalue) values(@tableName,@keyname,10000)
update TbGuidTable set keyvalue=keyvalue+1 where tablename=@tableName and keyname=@keyname
select @guid=cast(keyvalue as varchar) from TbGuidTable where tablename=@tableName and keyname=@keyname
Go ---*****---
declare @tableName varchar(50)
declare @keyname varchar(100)
declare @guid varchar(100)
set @tableName='tb1'
set @keyname='def'
execute PCreateGuid @tableName,@guid out
print @guid

原文链接:https://www.f2er.com/mssql/63881.html

猜你在找的MsSQL相关文章