如何在sql中添加16位自动增量字段? [英] How to add a 16 digit auto incremental field in sql?

查看:103
本文介绍了如何在sql中添加16位自动增量字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在sql中添加16位自动增量字段?我想在vc 2010中创建一个应用程序,它有3个字段,名称,出生日期和密码。如果用户提供包括密码的所有信息,则应将其插入数据库中。但是,唯一的id字段将使用密码(6位)+16位自动更新。例如,如果用户给出的密码为641001,那么它应该被添加为6410010000000001,如果另一个具有相同密码的用户进入细节,那么它应该被添加为6410010000000002。如果另一个用户具有不同的密码552145然后它应该被添加为5521450000000001 ..等等..它应该检查pincode如果已经存在,然后添加1到最后一个数字和更新它。并且它应该是唯一的。

How to add a 16 digit auto incremental field in sql? I would like to create an application in vc 2010 which has 3 fields, name, date of birth and pincode. If user gives all the information including the pin code, it should be inserted in the database. But the unique id field will be updated automatically with the pincode (6 digit)+ 16 digit.. For instance, if the user gives the pincode as 641001 then, it should be added as 6410010000000001, and if another user with same pin code enters the details, then it should be added as 6410010000000002. And if another user with different pincode 552145 then it should be added as 5521450000000001.. and so on.. It should check for pincode if already exists, then add 1 to the last digit and update it. and it should be unique.

推荐答案

我不建议这样做(尝试在你的主要领域放置几个信息)。



为什么你不使用简单的整数主键,并将你的密码/等级存储在另一列?



主键的目标是识别没有歧义的唯一记录;试图在其中添加更多信息会给你带来更多问题而不是解决。



另外,主键被编入索引;如果你使用一个大值作为主键,你将因索引维护而遭受巨大的性能损失。



所以我不打算给出一个解决方案以你分析它的方式解决问题。您应该检查您的设计并坚持有关数据库设计的众所周知的良好实践。
I don''t recommend to do that (trying to put several informations in your primary field).

Why don''t you use a simple integer primary key, and store your pincode/rank in another column ?

The goal of a primary key is to identify a unique record without ambiguity ; trying to put more informations in it will give you more problems than it will solve.

Plus, primary keys are indexed ; if you use a large value as a primary key, you will suffer huge performance losses due to maintenance of index.

So I''m not going to give a solution to your problem the way you have analyzed it. You should review your design and stick to well-known good practices regarding database design.


这篇关于如何在sql中添加16位自动增量字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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