我有这个奇怪的问题,我创建了一个有四列的表,并将一列设置为 int 类型的主键。我没有将主键列设置为标识,但是当我尝试在表中插入数据时出现此错误:
Cannot insert explicit value for identity column in table 'Table1' when IDENTITY_INSERT is set to OFF.
我尝试在不指定主键列的情况下插入(假设它设置为 IDENTITY(x,y)!),在这种情况下,它不会给出任何错误,但它也不会插入任何数据!
创建'table1':
USE [NEWVEDJA]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Table1](
[id] [int] NOT NULL,
[name] [nvarchar](50) NULL,
[code] [int] NULL,
[exp_1] [nvarchar](max) NULL,
CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
并插入“table1”
INSERT INTO [PARTIAL_NEWVEDJA].[dbo].[Table1]
([id]
,[name]
,[code]
,[exp_1])
VALUES
(1,N'سازمان',null,null), (2,N'معاونت',null,null);
GO
提前非常感谢。