SQL 插入没有值的表的语法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2148091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax for INSERTing into a table with no values?
提问by David Pfeffer
I have a table created with the following schema:
我有一个使用以下架构创建的表:
CREATE TABLE [dbo].[Visualizations]
(
VisualizationID int identity (1,1) NOT NULL
)
Since the table has no settable fields, I'm not sure how to insert a record. I tried:
由于该表没有可设置的字段,我不确定如何插入记录。我试过:
INSERT INTO [Visualizations];
INSERT INTO [Visualizations] () VALUES ();
Neither work. What is the proper syntax to do this?
都不工作。这样做的正确语法是什么?
Edit:Since a number of people seem confused by my table, it is used purely to represent a parent of a number of sub-tables... each one references this table by FK and each of those FKs are PKs, so that across all of those tables, the IDs are unique.
编辑:由于许多人似乎对我的表感到困惑,因此它纯粹用于表示许多子表的父表......每个表都由 FK 引用,并且每个 FK 都是 PK,因此在所有子表中在这些表中,ID 是唯一的。
回答by Anton Gogolev
回答by Sophie88
Trigger the identity insert with null
用 null 触发身份插入
insert into
Visualizations
values
(null);
回答by t0mm13b
Maybe you need to add a dummy column to do this, and just insert NULL
into it, the dummy column would allow for NULLs. Although your table structure does not make sense, I would suggest this in order for it to work.
也许您需要添加一个虚拟列来执行此操作,然后插入NULL
其中,虚拟列将允许 NULL。尽管您的表结构没有意义,但我建议这样做以使其正常工作。