Populate a self-referencing table
Last modified: October 8, 2024
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
In such situations, we recommend selecting the Disable Foreign Key option in the Data Generator project settings.
Was this page helpful?
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by Data Generator for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.