如何创建自定义主键? [英] How do i create a custom primary key?

查看:80
本文介绍了如何创建自定义主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,



请帮助我完成我的项目,我想在我的数据库设计中创建一个自定义主键,

格式是[当前年份] [当前月份] [3位数计数器]。

这就是这样的事情==> 201602001.下一个id应该是201602002等等,但这里是catch,下个月它应该显示==> 201603001然后下一个id应该是201603002,依此类推。三位数计数器应每月重置为001。



这可能吗?



提前谢谢....



我尝试了什么:



我是编程新手,凭借我的有限知识,我处于死胡同。我考虑创建另一个表来创建所需的格式,但它将是现有pk的冗余。谢谢

Good Day to all,

Please help me with my project, I would like to create a Custom Primary Key in my database design,
the format is [current year][current month][3 digit counter].
This goes something like this ==> 201602001. Next id should be 201602002 and so on, but here is the catch, the following month it should display ==> 201603001 then next id should be 201603002 and so on. The three digit counter should reset to 001 every month.

Is this possible?

Thank you in advance....

What I have tried:

I am new to programming and with my limited knowledge I was in the dead end. I consider creating another table to create that desired format but it would be a redundancy to the existing pk. Thank you

推荐答案

请阅读:使用SQL Server自定义自动生成的序列 - SQLTeam.com [ ^ ]然后根据需要进行更改。
Please, read this: Custom Auto-Generated Sequences with SQL Server - SQLTeam.com[^] then change it to your needs.


这篇关于如何创建自定义主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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