保持全球唯一身份 [英] maintain a global uniqe id

查看:64
本文介绍了保持全球唯一身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在将requestId保存到数据库中的同时将唯一键保存到数据库中。 RequestId意味着客户端向服务器生成的每个请求都应该有唯一的id。目前我正在使用Guid作为id但是guid会生成一个复杂的字符串作为id

请帮助我

提前感谢

how can i maintain a unique key into the database while saving requestId into the database. RequestId that means for every request generated by client to server there should be an unique id. currently I am using Guid for id but guid generates a complicated string as id
please help me
thanks in advance

推荐答案

GUID是常用的解决方案。如果您不喜欢它,请尝试使用线程ID处理id并附加时间戳。
GUID is the commonly used solution. If you dont like it then try process id with thread id and append timestamp.


您使用另一个表来保存globel id。



you acn use another table to hold on the globel id.

table_globel_id<br />
@id as bigint





每当插入到任何表使用此表中的ID

喜欢:从table_globel_id中选择isnull(id,0)



并且每当complitiong sql query / transaction 增加 table_globel_id 中的id值。 />


喜欢:



whenever inserting to any table use ID from this table
like: select isnull(id,0) from table_globel_id

and whenever complitiong the sql query/transaction increase the value of the id in table_globel_id.

like:

if exixt(select * from table_globel_id)
 then 
update table_globel_id set id=id+1
else
insert into table_globel_id(id)=1 


这篇关于保持全球唯一身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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