0

如果我有下表定义:

CREATE TABLE [dbo].[Application] (
    [ApplicationId]   INT            IDENTITY (1, 1) NOT NULL,
    [Name] NVARCHAR (MAX) NULL,
    CONSTRAINT [PK_dbo.Application] PRIMARY KEY CLUSTERED ([ApplicationId] ASC)
);

是否可以插入我自己的测试数据并覆盖标识列?我问的原因是因为我需要像这样填充几个表,并且我想获取每个表中的 ID 列以匹配外键?

如果这是不可能的,那么我可以插入数据然后将其更改为标识列吗?如果有人能给我一个例子,我会很高兴。

4

2 回答 2

4
SET IDENTITY_INSERT Application ON

INSERT INTO Application(ApplicationId, Name)
VALUES (3, 'Third Row')

SET IDENTITY_INSERT Application OFF
于 2013-02-26T13:16:28.483 回答
1
SET IDENTITY_INSERT Application ON

[Do your insert]

SET IDENTITY_INSERT Application OFF
于 2013-02-26T13:16:39.623 回答