交易ID创建逻辑 [英] Transaction Id Creation Logic

查看:86
本文介绍了交易ID创建逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我有一个系统,我想每天创建唯一的ID。

每日交易ID应该开始with 1



ex:

今天

260614 0001

260614 0002

260614 0003

260614 0004
260614 0005

260614 0006

.......

260614 0010



明天

270614 0001

270614 0002

270614 0003

270614 0004

270614 0005

270614 0006

.......

270614 0010



这是我到目前为止所做的...

 USE [BPOPortal] 
GO
/ ******对象:StoredProcedure [dbo]。[GetScanId]脚本日期:2014年6月26日下午3:39:22 * ***** /
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo]。[GetScanId]
@id int ,
@dtTime datetime
AS
BEGIN
if @ id = 1
begin
set @ dtTime = GETDATE()
--set @ dtTime =' 06/17/2014'

声明@TransactionId varchar(20)
声明@EScanId varchar(20)
begin tran


if(从EScantbl中选择Top(1)CONVERT(date,[DateTime],110))= CONVERT(date,@ dtTime,110)
begin
set @TransactionId =(select Top(1)ScanId来自于ID的上传大师订单)
set @TransactionId = Convert(int,SUBSTRING(@TransactionId,LEN(@TransactionId)-3,4))
set @ EScanId =(从EScantbl中选择EScanId)
update EScantbl set EScanId = EScanId + 1
select @ TransactionId + 1 as EScanId
end
else
begin
update EScantbl set EScanId ='001', [DateTime] = @ dtTime
从EScantbl中选择EScanId
结束
结束
其他
开始
选择1
结束
提交
结束





以上代码完美无缺,但问题是当我有并发用户试图获取Tran时sactionId有时会因为创建相同的Transactionid两次而失败。



这种情况​​经常发生,在300个案例中几乎是5次。

但是它错误的代码对我而言,因为交易ID正在重复。

有人请帮助。



先谢谢,

SUNIL MALI。

解决方案

检查以下答案

生成字母数字标识 [ ^

Dear All,

I have a system and i want to create unique id's on daily basis.
Daily Transaction id should start with 1

ex:
Today
2606140001
2606140002
2606140003
2606140004
2606140005
2606140006
.......
2606140010

Tomorrow
2706140001
2706140002
2706140003
2706140004
2706140005
2706140006
.......
2706140010

Here is what i have done so far...

USE [BPOPortal]
GO
/****** Object:  StoredProcedure [dbo].[GetScanId]    Script Date: 6/26/2014 3:39:22 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetScanId]
@id int,
	@dtTime datetime
AS
BEGIN
if @id=1
begin
set @dtTime=GETDATE()
--set @dtTime='06/17/2014'

declare @TransactionId varchar(20)
declare @EScanId varchar(20)
begin tran


	if (select Top(1) CONVERT(date,[DateTime],110) from EScantbl)=CONVERT(date,@dtTime,110)
	begin
			set @TransactionId=(select Top(1) ScanId from UploadMaster order by id desc)
			set @TransactionId=Convert(int,SUBSTRING(@TransactionId,LEN(@TransactionId)-3,4))
			set @EScanId=(select EScanId from EScantbl)
			update EScantbl set EScanId=EScanId+1
				select @TransactionId+1 as EScanId
	end
	else
	begin
		update EScantbl set EScanId='001' ,[DateTime]=@dtTime
		select EScanId from EScantbl
	end
end
else 
begin
	select 1
end
commit
 end



Above code works perfectly but the issue is when i have concurrent users trying to get TransactionId sometimes it fails by creating same Transactionid twice.

This happens very frequently, its nearly 5 times out of 300 cases.
But its bad Code for me as Transaction Id is repeating.
Somebody please help.

Thanks In Advance,
SUNIL MALI.

解决方案

check below answer
Generate a Alphanumeric ID[^]


这篇关于交易ID创建逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆