数据库取自增ID

之前仅仅用select count(*)+1 counts from table,今天保存数据是报唯一键约束,又搞了个方法:select isnull(max(convert(int,ID))+1,0) from table,希望能解决。如果要求ID前加个字母,如'E123',则使用:select  'E'+convert(varchar(15),isnull(max(convert(int,substring(case len(isnull(ID,'')) when 0 then 'E0' end,2,len(case len(isnull(ID,'')) when 0 then 'E0' end)-1))+1),1)) ID from  table
posted @ 2009-06-29 18:23  鱼肚白  阅读(220)  评论(0编辑  收藏  举报