且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SQL Server中自动生成主键入formate 1111abcd

更新时间:2022-06-20 17:49:25

sql不提供这种内置功能
您应该为此任务创建sql函数

首先创建表"alphanum"
sql doesn''t provide this kind of inbuilt functionality
you should create sql-function for this task

first create table ''alphanum''
intval  alphaval
----------------
1       a
2       b
3       c
.       .
.       .
.       .
26      z



函数具有参数('''')
然后返回"1111aaaa"
其他
假设是"1111aaaa",那么
分割最后四个字母数字
按desc顺序创建for循环

从"alphanum"表中获取alphaval的整数值
检查intval是否为26,然后将其重置为1,并用1递增下一个alphaval.

通过这种方式构建逻辑并创建自己的字母数字主键" sql函数

祝您编码愉快!
:)



a function have parameter('''')
then return ''1111aaaa''
else
suppose ''1111aaaa'' then
split last four alpha numbers
create for loop in desc order

fetch intvalue for the alphaval from ''alphanum'' table
check if intval is 26 then reset it to one and increment next alphaval with 1.

this way build logic and create your own ''alphanumeric primary key'' sql-function

Happy Coding!
:)