将行插入 table 只有一列、主键和标识
Insert row into table with only one column, primary key and identity
这里有一个table定义:
CREATE TABLE dbo.TableOnlyPK
(
Id tinyint PRIMARY KEY IDENTITY (1, 1)
)
现在我需要通过 T-SQL 语句将行插入到 table 中:我尝试了几种解决方案,但没有一个有效。
INSERT INTO dbo.TableOnlyPK () VALUES () -- not worked
尝试:
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
您创建了以下 table:
CREATE TABLE dbo.TableOnlyPK
(
Id tinyint PRIMARY KEY IDENTITY (1, 1)
)
每次触发:INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
,您将在 IDENTITY 列中插入一行。
所以如果你执行:
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
结果将是:
INSERT INTO [dbo].[TableOnlyPK]
DEFAULT VALUES
这里有一个table定义:
CREATE TABLE dbo.TableOnlyPK
(
Id tinyint PRIMARY KEY IDENTITY (1, 1)
)
现在我需要通过 T-SQL 语句将行插入到 table 中:我尝试了几种解决方案,但没有一个有效。
INSERT INTO dbo.TableOnlyPK () VALUES () -- not worked
尝试:
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
您创建了以下 table:
CREATE TABLE dbo.TableOnlyPK
(
Id tinyint PRIMARY KEY IDENTITY (1, 1)
)
每次触发:INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
,您将在 IDENTITY 列中插入一行。
所以如果你执行:
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
INSERT INTO dbo.TableOnlyPK DEFAULT VALUES
结果将是:
INSERT INTO [dbo].[TableOnlyPK]
DEFAULT VALUES