如何在SQL Server中自动生成主键入formate 1111abcd [英] how to auto generate primary keyin formate 1111abcd in sql server

查看:107
本文介绍了如何在SQL Server中自动生成主键入formate 1111abcd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
如何在SQL Server中自动生成主键输入格式1111abcd并像
自动生成

hello
how to auto generate primary keyin formate 1111abcd in sql server and autogenerate like

1111abcd .1111abce,,,,,,,,,,,,,,.....
..upto..1111zzzz,1112aaaa.


请给我一些帮助


please give me some help

推荐答案

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!
:)


这篇关于如何在SQL Server中自动生成主键入formate 1111abcd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆