SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrimaryTable](
[Id1] [int] NOT NULL,
[id2] [int] NOT NULL,
[data] [nchar](10) NULL,
CONSTRAINT [PK_PrimaryTable] PRIMARY KEY CLUSTERED
(
[Id1] ASC,
[id2] 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
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ForeignTable](
[id1] [int] NOT NULL,
[id2] [int] NOT NULL,
[Refernencedata] [nchar](10) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ForeignTable] WITH CHECK ADD CONSTRAINT [FK_ForeignTable_PrimaryTable] FOREIGN KEY([id1], [id2])
REFERENCES [dbo].[PrimaryTable] ([Id1], [id2])
GO
ALTER TABLE [dbo].[ForeignTable] CHECK CONSTRAINT [FK_ForeignTable_PrimaryTable]
GO
I created rough script for you please check if you are looking for this. I would suggest try first without data in the tables so that you do not get the data related issues and then check if there is existing records which are not allowing you to create foreign keys.