-- Description: 创建各个模块的新ID
-- =============================================
ALTER PROCEDURE [dbo].[SP_INV_NEW_ID_CREATE]
@MODULE_ID_KEY NVARCHAR(20) --模块ID在SYSTEM_CONFIG表中的关键字
AS
BEGIN
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
DECLARE @OLD_ID INT
DECLARE @NEW_ID INT
BEGIN TRAN
----首先查找出本模块现在的ID
SELECT @OLD_ID=CONVERT(INT,CFG_VALUE)
FROM SYSTEM_CONFIG (ROWLOCK)
WHERE CFG_NAME=@MODULE_ID_KEY
--新ID=旧ID+1
SET @NEW_ID=@OLD_ID+1
--回写到SYSTEM_CONFIG表中
UPDATE SYSTEM_CONFIG WITH(ROWLOCK)
SET CFG_VALUE=CONVERT(NVARCHAR(100),@NEW_ID)
WHERE CFG_NAME=@MODULE_ID_KEY
COMMIT TRAN
IF(@@ERROR<>0)
ROLLBACK TRAN
--返回新的ID
SELECT @NEW_ID AS NEW_ID
END