一个主键。两个外键,
把两个外键改为非空就行了。
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