server的自增主键返回函数 sql_SQL自增主键函数
生活随笔
收集整理的這篇文章主要介紹了
server的自增主键返回函数 sql_SQL自增主键函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
自動生成編碼的主鍵函數
比如
CRM00001
CRM00002
CRM00003
create table IntKey(KeyChar char(10))
go
create function GetKey()
returns char(10)
as
begin
declare @KeyValue int
declare @KeyReturn varchar(20)
set @KeyValue = cast(isnull((select max(KeyChar) from IntKey),0) as int) + 1
set @KeyReturn = '000000000 ' + ltrim(str(@KeyValue))
return right(@KeyReturn,10)
end
go
declare @i int
set @i = 0
while @i < 100
begin
insert into IntKey(KeyChar)
select dbo.GetKey()
set @i = @i + 1
end
select * from IntKey
go
drop function GetKey
drop table IntKey
總結
以上是生活随笔為你收集整理的server的自增主键返回函数 sql_SQL自增主键函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++匿名对象
- 下一篇: 海美迪盒子android升级包,海美迪H