插入 id(自动生成,仅列) [英] Insert id (autogenerated, only column)

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

问题描述

如果我不想在表中插入一行,而该表只包含一个带有自动生成 ID 的列,那么我的 SQL 语句 (MS-SQL) 应该是什么样的?

How should my SQL-Statement (MS-SQL) look like if I wan't to insert a row into a table, which contains only one column with the autogenerated id?

以下两个查询不起作用:

Following two queries won't work:

INSERT INTO MyTable (MyTableId) VALUES (Null)
-- or simply
INSERT INTO MyTable 

感谢任何提示.sl3dg3

Thx for any tipps. sl3dg3

推荐答案

INSERT INTO MyTable (MyTableId) VALUES (Null) 隐式地尝试在标识列中插入一个空值,这样就不会作为标识列可能永远不能为空,如果没有 SET 选项,您无论如何都无法插入任意值,而是可以使用:

INSERT INTO MyTable (MyTableId) VALUES (Null) implicitly tries to insert a null into the identity column, so that won't work as identity columns may never be nullable and without a SET option you cannot insert an arbitrary value anyway, instead you can use:

INSERT INTO MyTable DEFAULT VALUES

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

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