Populate a table referencing another table that already contains data
Last modified: October 8, 2024
When trying to populate a table with circular reference and not including a table it references to data generation, the following error will be displayed:
Column refers to X column of Y table which is not included in the data generation.
The following example illustrates tables with circular reference:
CREATE TABLE dbo.reference_in_table1 (
ID int NOT NULL,
clm_ref1 int NOT NULL UNIQUE,
PRIMARY KEY CLUSTERED (ID)
)
ON [PRIMARY]
GO
CREATE TABLE dbo.reference_in_table2 (
ID int NOT NULL,
clm_ref1 int NOT NULL UNIQUE,
PRIMARY KEY CLUSTERED (ID)
)
ON [PRIMARY]
GO
ALTER TABLE dbo.reference_in_table1 WITH NOCHECK
ADD FOREIGN KEY (clm_ref1) REFERENCES dbo.reference_in_table2 (clm_ref1)
GO
ALTER TABLE dbo.reference_in_table2 WITH NOCHECK
ADD FOREIGN KEY (clm_ref1) REFERENCES dbo.reference_in_table1 (clm_ref1)
GO
This happens when you don’t want to populate the second table as it already contains data and don’t include it in data generation.
To solve this issue, we recommend changing the Foreign Key (auto assigned) generator for the Table or View generator.
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.