Populate a self-referencing table

The following example illustrates a table that has foreign key references to itself:

CREATE TABLE dbo.references_in_table (
ID int NOT NULL,
clm_ref1 int NOT NULL,
PRIMARY KEY CLUSTERED (ID)
)
ON [PRIMARY]
GO

ALTER TABLE dbo.references_in_table WITH NOCHECK
ADD FOREIGN KEY (clm_ref1) REFERENCES dbo.references_in_table (ID)
GO

When trying to populate a table that has a self-referencing foreign key, you will encounter the following warning:

The table contains the self-referencing foreign key. It is recommended to enable the Disable Foreign Key option

Population warning

In such situations, we recommend selecting the Disable Foreign Key option in the Data Generator project settings.