自动生成用户ID [英] auto generate user id

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

问题描述

嗨我有一个data.sdf附加到我的数据输入表单,当我在datagridview中输入数据时,我希望userid按升序自动生成

hi I have a database.sdf attached to my data entry form, when I input data in the datagridview, I would like the userid to auto generate in ascending order

推荐答案

在您的数据库架构中设置一列以使用 IDENTITY 属性

例如

In your database schema have one column set up to use the IDENTITY property
e.g.
create table myTable(
ID int not null IDENTITY(1,1)
-- other columns ...
)



这将自动创建一个ID从1 1 ,1)开始,每次添加一行时递增1 (1, 1 的)。它将自动处理从表中删除的任何行,确保ID始终是唯一的。



请参阅此链接 [ ^ ]文档


This will automatically create an ID starting at 1 (1,1) and incrementing by 1 each time a row is added (1,1). It will automatically handle any rows that are deleted from the table ensuring that the ID is always unique.

See this link[^] for the documentation


用户与解决方案1中的相同。



但你可以做我的查询。



只执行一个选择查询b4插入查询



SELECT COUNT(用户名)+1 AS''NewId''FROM xyzTabel



现在用户NewId和Newid为您的新用户
user the same as given in Solution 1 .

but you can do it my query .

just execute an select query b4 the insert query

SELECT COUNT(username)+1 AS ''NewId'' FROM xyzTabel

And now user NewId as and Newidfor your new user


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

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