如何插入只有一个 IDENTITY 列的表 (SQL Express)
Pretty much the same as this question.
But I can't seem to get this to work with SQL Server Express in Visual Studio 2008.
Same Table layout, One column with identity and primary key.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我来说效果很好。您如何尝试将这些行放入数据库? SQL Server 管理工作室?来自 .NET 应用程序的 SQL 查询?
在 Visual Studio 的“新查询”窗口中运行,我得到:
==>好的,Visual Studio 无法处理它 - 这不是 SQL Server 的错,而是 Visual Studio 的错。请使用真正的 SQL Management Studio - 它在那里工作得很好!
使用 ADO.NET 也很有魅力:
似乎是 VS 的限制 - 不要使用 VS 进行严肃的数据库工作:-)
马克
This works just fine in my case. How are you trying to get those rows into the database? SQL Server Mgmt Studio? SQL query from .NET app?
Running inside Visual Studio in the "New Query" window, I get:
==> OK, so Visual Studio can't handle it - that's not the fault of SQL Server, but of Visual Studio. Use the real SQL Management Studio instead - it works just fine there!
Using ADO.NET also works like a charm:
Seems to be a limitation of VS - don't use VS for serious DB work :-)
Marc
与其尝试依赖有关“DEFAULT VALUES”的某些语法作为关键字,不如让引擎帮助您...不如显式尝试设置其中一个值(例如
So),即使您只准备一个字段,本机引擎的新记录应该用它们各自的默认值填充它们的其余部分。
Instead of trying to rely on some syntax about "DEFAULT VALUES" as the keyword, let the engine help you with that... How about explicitly trying to set ONE of the values, such as
So, even though you are only preping ONE field, the new record by the native engine SHOULD populate the REST of them with their respective default values.