Copy codeThe Code is as follows:
Create table [dbo]. [TbGuidTable] (
[TableName] [varchar] (50) not null,
[KeyName] [varchar] (20) not null,
[KeyValue] [varchar] (100) 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
------------------------------------
-- Purpose: Add a record of personal information
-- Project name:
-- Note:
-- Time: 15:34:12
------------------------------------
Create procedure PCreateGuid
@ TableName varchar (50 ),
@ Key name 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, @ keyname, @ guid out
Print @ guid