当 IDENTITY_INSERT 设置为 OFF 时,不能向表 中的标识列插入显式值错误的解决方法

一个主键。两个外键,
把两个外键改为非空就行了。

CREATE TABLE [dbo].[User_Compare](
[Id] [int] IDENTITY(1,1) NOT NULL,
[UserId] [int] NOT NULL,
[PatentId] [int] NOT NULL,
CONSTRAINT [PK_User_Compare] 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 ALTER TABLE [dbo].[User_Compare] WITH CHECK ADD CONSTRAINT [FK_User_Compare_Patents] FOREIGN KEY([PatentId])
REFERENCES [dbo].[Patents] ([Id])
GO ALTER TABLE [dbo].[User_Compare] CHECK CONSTRAINT [FK_User_Compare_Patents]
GO ALTER TABLE [dbo].[User_Compare] WITH CHECK ADD CONSTRAINT [FK_User_Compare_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[Users] ([Id])
GO ALTER TABLE [dbo].[User_Compare] CHECK CONSTRAINT [FK_User_Compare_Users]
GO
上一篇:第八节:常见安全隐患和传统的基于Session和Token的安全校验


下一篇:[转帖]彻底理解cookie,session,token