如何修改ID自动增量 [英] How to modify ID auto increment

查看:92
本文介绍了如何修改ID自动增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有id增量'1,2,3 ......'但是我想把它们放在数据库中的变量MemberNumber中并修改为00001 +天+年(2)

i试试

I have id increment '1,2,3...' but I wanna get them in variable MemberNumber in database and modify as 00001+days+year(2)
i have try

search.MemberNumber = search.Id.ToString("0000") + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString();



但是Id仍然给我'0'而年份给4位数。



如果你可以解决这个问题请教我,我很欣赏它。谢谢


but Id still give me '0' and Year give 4 digits.

if you can solve this please teach me and im very appreciate it. Thank you

推荐答案

如果我理解你的问题,你就要在一个字段中存储多个数据项(自动增量,日期编号,年份等)。如果是这种情况,我建议不要这样做。



让id(密钥)只是一个生成的,无意义的数字,只有一个识别记录的目的。换句话说,让它成为代理键 [ ^ ]。还将其他数据suhc作为日期等存储在单独的字段中。



生成ID号后,让数据库处理它。您可以使用例如列的标识定义。请参阅身份 [ ^ ]
If I understand your question correctly, you're about to store multiple data items (auto increment, day number, year etc) in a single field. If this is the case, I would advice not to do this.

Let the id (the key) be just a generated, non-meaningful number which has the only purpose of identifying the record. In other words let it be a surrogate key[^]. Also store the other data suhc as dates and so on in separate fields.

What comes to the ID number generation, let the database handle it. You can use for example identity definition for the column. See Identity[^]


这篇关于如何修改ID自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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