自动递增编号 [英] Auto Incrementing number

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

问题描述

大家好,

有人可以告诉我如何使用linq为sql数据字段创建自动递增编号吗?

在此先感谢您.

Hi all,

Can anybody tell me how to create an Auto Incrementing number for an sql data field using linq?

Thanks in advance.

推荐答案

您不需要这样做-数据库会创建和维护Sql AutoNumner字段.您不能在代码中分配它们-这就是重点!

根据您的操作,您可能需要考虑使用Guids而不是自动编号-如果插入一条记录,则必须找到它以在其他地方使用它的自动编号字段,然后绝对要考虑使用Guid.它们具有很多优点,尤其是在复制方面.

当您不需要再次引用记录时,自动编号可以用于日志表(等等),但仅此而已!
You don''t need to do it - Sql AutoNumner fields are created and maintained by the database. You cannot assign them in your code - that is the whole point!

Depending on what you are doing, you may want to consider using Guids rather than autonumber - If you insert a record, then have to find it to use it''s autonumber field elsewhere, then definitely look at Guid instead. They have a lot of advantages, particularly when it comes to replication.

Autonumber is fine for a log table (and so forth) when you don''t need to refer to the record again, but that''s about it!


您最好离开这留给数据库-您正在使用SQL Server?

如果是这样,请使用整数数据类型创建一个字段,然后在设计器中将其设置为Identity = Yes.

每当添加新记录时,该字段都会自动递增.
You''re best off leaving this to the database - are you using SQL Server?

If so, create a field with an integer data type and set it to Identity = Yes in the designer.

Whenever a new record is added, this field will auto increment.


我建​​议让SQL Server使用自动编号来进行递增编号.在多用户系统的情况下,由于重复插入而导致的错误.

:):)
I would suggest let SQL Server do the incremental numbering by using autonumber.In your scenario if you will do from front end then chances on duplicate inserts due in case of multiuser system.

:) :)


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

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