无法通过 SQL Server Express Management Studio 设置自动增量?

发布于 2024-10-06 15:09:25 字数 504 浏览 0 评论 0原文

我只是尝试将值插入数据库并且可以工作。现在我再次插入,并收到相同主键的错误。

我找不到任何选项可以将其更改为自动增量。

我正在通过 Linq-To-Sql 更新表。

User u = new User(email.Text, HttpContext.Current.Request.UserHostAddress,
                                        CalculateMD5Hash(password.Text));
db.Users.InsertOnSubmit(g);
db.SubmitChanges();

我没有填写user_id,第一次运行得很好。它变成了零。 尝试添加第二个用户时,它想再次使 ID 为 0。

我可以查询数据库并询问最高的 ID,但如果您了解自动增量,那就太远了。

我怎样才能打开这个功能?我能找到的只是用于创建表的脚本。我想保留现有的表格并简单地对其进行编辑。

I just tried inserting value in to a database and that work. Now I insert again and I get an error for identical primary key.

I can't find any option to alter it to be auto-increment.

I'm updating the table via Linq-To-Sql.

User u = new User(email.Text, HttpContext.Current.Request.UserHostAddress,
                                        CalculateMD5Hash(password.Text));
db.Users.InsertOnSubmit(g);
db.SubmitChanges();

I didn't fill in the user_id and it worked fine the first time. It became zero.
Trying to add a second user, it wants to make the ID 0 again.

I could query the database and ask for the highest ID, but that's going to far if you know about auto-increment.

How can I turn this on? All I can find are scripts for table creation. I'd like to keep my existing table and simply edit it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

↘人皮目录ツ 2024-10-13 15:09:25

您的 Linq-to-SQL 模型是如何定义的?检查 user_id 列的属性 - 它们设置为什么?

alt text

在您的 Linq-to-SQL 模型中,请务必设置自动生成的值 ,将 Auto-Sync 设置为 OnInsert,并且服务器数据类型也应与您的设置 (INT IDENTITY) 匹配

在 SQL Server 管理中 Studio,您需要将 user_id 列定义为 INT IDENTITY 类型 - 在可视表设计器中,您需要在此处设置此属性:

替代文字

How is your Linq-to-SQL model defined?? Check the properties of the user_id column - what are they set to??

alt text

In your Linq-to-SQL model, be sure to have Auto Generated Value set to true, Auto-Sync set to OnInsert, and the server data type should also match your settings (INT IDENTITY),

In SQL Server Management Studio, you need to define the user_id column to be of type INT IDENTITY - in the visual table designer, you need to set this property here:

alt text

梦冥 2024-10-13 15:09:25

它为零,因为主键列类型有一个整数。要使用自动增量,请将表标识列设置为 ID(在表属性中选择)

It is zero because you have a integer for a primary key column type. To use auto-increment, set tables identity column to the ID (selected in the table properties)

淡写薰衣草的香 2024-10-13 15:09:25

如果你有一个适用的版本,使用 VS 编辑数据库可能会更容易,否则如果你必须在 Management Studio 中编辑它,请参阅这篇文章:
http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

Would probably be easier to edit the database using VS if you have a version that will work for, otherwise if you have to edit it in management studio see this article:
http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

苦笑流年记忆 2024-10-13 15:09:25

或者,如果您无法更改属性/表字段描述,您可以手动增加 user_id 并将其传递给插入函数

Or you can increment the user_id manually and pass it to the insert function if you cannot alter the property/table field description

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文