SQL Data Generator 4

Help for older versions available.

Self-referencing table constraints can cause generation to stop

When generating data against a table which has foreign key references to itself, the following error may occur:

Generation stopped. The generator for column [COLUMN] could not generate any more values

The following example illustrates a reproduction for this issue:

  1. CREATE TABLE [dbo].[Account]
  2. (
  3. [AccountID] [uniqueidentifier] NOT NULL,
  4. [AccountNumber] [nvarchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  5. [AccountName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
  6. [AccountType] [int] NOT NULL,
  7. [LedgerID] [uniqueidentifier] NULL,
  8. [UniqueID] [int] NOT NULL IDENTITY(1, 1),
  9. [Version] [datetime] NOT NULL,
  10. [FinYearID] [uniqueidentifier] NOT NULL
  11. )
  12.  
  13. GO
  14. ALTER TABLE [dbo].[Account] ADD CONSTRAINT [AccountTypeRule] CHECK (([AccountType]=(1) OR [AccountType]=(2) OR [AccountType]=(3) OR [AccountType]=(4) OR [AccountType]=(5)))
  15. GO
  16. ALTER TABLE [dbo].[Account] ADD CONSTRAINT [PK_Account] PRIMARY KEY CLUSTERED ([UniqueID])
  17. GO
  18. ALTER TABLE [dbo].[Account] ADD CONSTRAINT [UK_AccountID_FinYearID] UNIQUE NONCLUSTERED ([AccountID], [FinYearID])
  19. GO
  20. ALTER TABLE [dbo].[Account] ADD CONSTRAINT [UK_AccountName_FinYearID] UNIQUE NONCLUSTERED ([AccountName], [FinYearID])
  21. GO
  22. ALTER TABLE [dbo].[Account] ADD CONSTRAINT [FK_Account_FinancialYear] FOREIGN KEY ([FinYearID]) REFERENCES [dbo].[FinancialYear] ([FinYearID])
  23. GO
  24. ALTER TABLE [dbo].[Account] ADD CONSTRAINT [FK_LedgerID_AccountID] FOREIGN KEY ([LedgerID], [FinYearID]) REFERENCES [dbo].[Account] ([AccountID], [FinYearID])
  25. GO

This is a known issue and we are currently evaluating support for this scenario.


Didn't find what you were looking for?