获取唯一标识的几种方法

6 篇文章 0 订阅

获取唯一标识的几种方法

一 、 写序列

数据库创建
–** 创建流程ID序列
create sequence NURADM.NURADM_FLOW_SEQ

increment by 1//增长值

start with 1//起始值

nomaxvalue//最大值可以不写

nominvalue

nocache;
create public synonym NURADM_FLOW_SEQ for NURADM.NURADM_FLOW_SEQ;//需要创建同义词

c#
using TJHIS.Comm;
private DBSrv ws = new DBSrv();
///
/// 获取流程配置ID(序列)
///
///
public int GetFlowConfigID()
{
int csNo = ws.GetSeq(“NURADM_FLOW_SEQ”); //流程配置ID数据库序列
return csNo;
}

二 、 使用时间戳

using System;
//获取当前时间戳,理论上精确到毫秒时,不会有重复的数据
public string GetTimeStamp()
{
Random ran = new Random();
int RandKey = ran.Next(100, 1000);
DateTime dtNow = DateTime.Now;
return dtNow.ToString(“yyMMddHHmmss”) + dtNow.Millisecond.ToString() + RandKey.ToString();
}

三 、以实际数据库中的最大值做累加

///
/// 获取TYPE_ID的最大值并加1
///
///
public string ReturnMaxTypeId()
{
string typeid = string.Empty;
int int_type = 1000;
string sql = “select max(type_id) type_id from nr_SEVERE_type”;
DataSet ds = dbConn.SelectData(sql,true);
if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0][“type_id”].ToString().Trim().Trim().Length > 0)
{
int_type = Convert.ToInt32(ds.Tables[0].Rows[0][“type_id”].ToString()) + 1;
}
else
{
int_type = 1;
}
typeid = string.Format(“{0:00}”, int_type);
return typeid;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值