1

Closed

Can't recreate objects with circular references

description

Although you can script the definition, you can't excute the script and recreate objects with circular references.
Manually create:
CREATE TABLE [aaA]([val] [int] PRIMARY KEY)
CREATE TABLE [aaB]([val] [int] PRIMARY KEY)
ALTER TABLE [aaA]  WITH CHECK ADD  CONSTRAINT [FK_aaA_aaB] FOREIGN KEY([val]) REFERENCES [aaB] ([val])
ALTER TABLE [aaB]  WITH CHECK ADD  CONSTRAINT [FK_aaB_aaA] FOREIGN KEY([val]) REFERENCES [aaA] ([val])
Will script (roughly):
CREATE TABLE [aaB]([val] [int] PRIMARY KEY)
ALTER TABLE [aaB]  WITH CHECK ADD  CONSTRAINT [FK_aaB_aaA] FOREIGN KEY([val]) REFERENCES [aaA] ([val])
    ^Argh! aaA wasn't created yet!
CREATE TABLE [aaA]([val] [int] PRIMARY KEY)
ALTER TABLE [aaA]  WITH CHECK ADD  CONSTRAINT [FK_aaA_aaB] FOREIGN KEY([val]) REFERENCES [aaB] ([val])
 
We could possibly split TABLE and FOREIGN KEY definitions - but there could be other cyclic possibilities to consider as well.
Closed Mar 16, 2011 at 4:46 AM by ivanjh
Duplicate

comments