当前位置: 代码迷 >> ASP.NET >> 求ID字段生成算法,该怎么处理
  详细解决方案

求ID字段生成算法,该怎么处理

热度:1883   发布时间:2013-02-25 00:00:00.0
求ID字段生成算法
现需由系统产生一种唯一标识记录的ID字段,希望各位高手提供下...位数不限,但不能出现重复的概率...

------解决方案--------------------------------------------------------
自定义啊 
use test
go
if exists(select * from sysobjects where name='P_Order' and type='P' )
drop proc P_order
go
create proc P_Order
@MaxId int,
@Date varchar(10),
@NewId varchar(20)
as
begin
select @MaxId=Id from TB_Order
select @Date=CONVERT(VARCHAR(10),GETDATE(),112) 
set @NewId=@Date+ right(cast(power(10,4) as varchar)+@MaxId,4)
insert into dbo.test([Name],EName,[NewId]) values('lee','lfs',@NewId)
end

exec P_Order
------解决方案--------------------------------------------------------
HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""><script type="text/javascript">function UUID(){    this.id = this.createUUID();}UUID.prototype.valueOf = function(){ return this.id; }UUID.prototype.toString = function(){ return this.id; }UUID.prototype.createUUID = function(){      var dg = new Date(1582, 10, 15, 0, 0, 0, 0);    var dc = new Date();    var t = dc.getTime() - dg.getTime();    var tl = UUID.getIntegerBits(t,0,31);    var tm = UUID.getIntegerBits(t,32,47);    var thv = UUID.getIntegerBits(t,48,59) + '1'; // version 1, security version is 2    var csar = UUID.getIntegerBits(UUID.rand(4095),0,7);    var csl = UUID.getIntegerBits(UUID.rand(4095),0,7);    var n = UUID.getIntegerBits(UUID.rand(8191),0,7) +             UUID.getIntegerBits(UUID.rand(8191),8,15) +             UUID.getIntegerBits(UUID.rand(8191),0,7) +             UUID.getIntegerBits(UUID.rand(8191),8,15) +             UUID.getIntegerBits(UUID.rand(8191),0,15); // this last number is two octets long    return tl + tm  + thv  + csar + csl + n; }UUID.getIntegerBits = function(val,start,end){    var base16 = UUID.returnBase(val,16);    var quadArray = new Array();    var quadString = '';    var i = 0;    for(i=0;i<base16.length;i++){        quadArray.push(base16.substring(i,i+1));        }    for(i=Math.floor(start/4);i<=Math.floor(end/4);i++){        if(!quadArray[i] || quadArray[i] == '') quadString += '0';        else quadString += quadArray[i];    }    return quadString;}UUID.returnBase = function(number, base){    return (number).toString(base).toUpperCase();}UUID.rand = function(max){    return Math.floor(Math.random() * (max + 1));}function newUID(){    document.getElementById("txtUID").value = new UUID();}</script></HEAD><BODY><input type="text" id="txtUID" style="width:300px" value=""/><br/><input type="button" id="btnUID" value="Create UID" onclick="newUID();"/></BODY></HTML>
  相关解决方案