0
I am creating two references of Foreign key pointing to two different tables, however I am getting error in creating one of them.
There are no Primary or candidate Keys in the referenced table 'dbo.TB_PODERES' that match the referencing column list in the Foreign key 'FK_TB_GRUPOS_PODERES_PODERES_TB_PODERES'.
The reference table is as follows:
CREATE TABLE [dbo].[TB_PODERES](
[ID_PDR] [int] IDENTITY(1,1) NOT NULL,
[CD_PODER] [char](10) NOT NULL,
[NM_PODER] [varchar](100) NOT NULL,
[IC_ATIVO] [bit] NOT NULL,
[DT_ULT_ATUALIZACAO] [datetime] NOT NULL,
CONSTRAINT [PK_TB_PODERES_PODER] PRIMARY KEY NONCLUSTERED
(
[ID_PDR] ASC,
[CD_PODER] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
and the table I’m creating at FK is this.
CREATE TABLE [dbo].[TB_GRUPOS_PODERES_PODERES](
[ID_GPP] BIGINT IDENTITY(1,1) NOT NULL,
[ID_GRP_PDR] [bigint] NOT NULL,
[CD_PODER] [char](10) NOT NULL,
[IC_ATIVO] [bit] NOT NULL,
[DT_ULT_ATUALIZACAO] [datetime] NOT NULL,
PRIMARY KEY CLUSTERED
(
[ID_GPP],[ID_GRP_PDR],[CD_PODER] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
ALTER TABLE [dbo].TB_GRUPOS_PODERES_PODERES WITH CHECK ADD CONSTRAINT FK_TB_GRUPOS_PODERES_PODERES_TB_PODERES FOREIGN KEY([CD_PODER])
REFERENCES [dbo].TB_PODERES ([CD_PODER])
GO
ALTER TABLE [dbo].TB_GRUPOS_PODERES_PODERES CHECK CONSTRAINT FK_TB_GRUPOS_PODERES_PODERES_TB_PODERES
GO
Check that the primary key of the table TB_PODERES is actually the pair (ID_PDR, CD_PODER). If it is, which column in table TB_GRUPOS_PODERES_PODERES refers to column ID_PDR in table TB_PODERES?
– José Diz