自动生成数字 [英] generate automatically number

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

问题描述

我使用VB.net 2008和Sql db作为后端

在这个软件上我试图自动生成数字作为唯一号码或ID

你可以帮我做这个

i m using VB.net 2008 and Sql db as backend
on this software i m trying to generate automatically number as unique number or ID
can you help me on doing this

推荐答案

在SSMS中编辑数据库,并在表中添加一个ID列:将其设置为int,并将Column Properties窗口向下滚动到Identity规格。

单击[+]展开属性,然后双击(Is Identity)将其从No更改为Yes。

保存你的桌子。



SQL Server现在每次保存一行时都会提供一个新的ID值,并确保它是唯一的。

请注意,您不能依赖当前值作为 next 值的指标:如果您尝试了,您将可以正常进行测试,但是当您完成时,整个过程将会崩溃有多个用户。只有在插入行后才尝试使用ID值。
Edit your DB in SSMS, and add an ID column to your table: Set it as "int", and scroll the Column Properties window down to "Identity Specification".
Click the [+] to expand the property, and double click "(Is Identity)" to change it from "No" to "Yes".
Save your table.

SQL server will now provide a new ID value every time you save a row and will ensure that it is unique.
Do note that you cannot rely on the current value as an indicator of what the next value will be: if you do try you will work OK for testing, but the whole thing will collapse in production when you have more than one user. Only ever try to use an ID value after the row has been inserted.


如果你想要一个全局唯一的唯一号码,你可以在SQL中使用NEWID()函数。



If you want a unique number that's globally unique you can use the NEWID() function in SQL.

SELECT NEWID()





会给你一个看起来像C7E987A9-958C-4A4C-95EC-E2AAEA6E0C08的GUID



will give you a GUID that looks like C7E987A9-958C-4A4C-95EC-E2AAEA6E0C08


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

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