如何在不使用IDENTITY的情况下自动增加列? [英] How can I auto-increment a column without using IDENTITY?

查看:110
本文介绍了如何在不使用IDENTITY的情况下自动增加列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用IDENTITY属性的情况下自动增加列?



我创建了一个包含IDENTITY列的表。但我面临身份价值跳跃问题。我想在不使用IDENTITY属性的情况下创建自动增量列。



使用NEWID函数是否有用?

How can I auto-increment a column without using IDENTITY property?

I have created a table with IDENTITY column. But i am facing identity value jump issue. I want to create auto-increment column without using IDENTITY property.

Is it useful to use NEWID function?

推荐答案

NEWID - 创建uniqueidentifier类型的唯一值。如果你想要唯一的值,那么就可以使用它,但它不会自动增加。



你可以在SQL SERVER中使用另一个概念。这就是Sequence。



在SQL Server中创建序列并在表格列中使用该序列。



https://www.simple-talk.com/sql/learn -sql-server / sql-server-sequence-basics / [ ^ ]
NEWID - Creates a unique value of type uniqueidentifier. If you want unique value then can use it but it is not auto incremented.

You can use another concept in SQL SERVER. That is Sequence.

Create Sequence in SQL Server and use that Sequence in your table column.

https://www.simple-talk.com/sql/learn-sql-server/sql-server-sequence-basics/[^]


我同意ManasKumarM。

但我想如果你有一个身份的跳跃问题,可能你也会有序列。

我想你的代码或你的流程中有东西保留下一个身份并且不使用它。就像回滚或取消请求一样。

可能是吗?
I agree with ManasKumarM.
But I think that if you have a "jump" issue with identity, probably You will have with sequence too.
I suppose you have something in your code or in your flow that reserves the next identity and does not use it. Like a "rollback" or a "cancel" request.
May be?


这篇关于如何在不使用IDENTITY的情况下自动增加列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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