0
Answered

Reference issue when generating SQL server script

nikhil.android.dev 2 years ago updated by Support 2 years ago 2

First of all thanks a ton for the awesome tool. This is first time I tried to implement this tool so bit novice here.

When I tried to generate SQL Server script it gives me reference related error i.e it try to give a reference the table that haven't been created yet.

I have checked the generated script, it references at time of table creation so if the table is not created earlier it gives error. Instead of it should be first create all table then alter table for referencing.

please see below code 

CREATE TABLE [dbo].[MstLanguage]
(
 [LanguageId]   INT NOT NULL ,
 [LanguageName] VARCHAR(50) NULL ,
 CONSTRAINT [PK_Language] PRIMARY KEY CLUSTERED ([LanguageId] ASC)
);
GO
--************************************** [dbo].[TrnLanguage]
CREATE TABLE [dbo].[TrnLanguage]
(
 [Langu]      INT NOT NULL ,
 [LanguageId] INT NOT NULL ,
 CONSTRAINT [PK_TrnLanguage] PRIMARY KEY CLUSTERED ([Langu] ASC),
 CONSTRAINT [FK_722] FOREIGN KEY ([LanguageId])
  REFERENCES [dbo].[MstLanguage]([LanguageId])
);
GO


Please guid me may be I am doing something wrong. 
Thanks in advance. 

Answered

I tested the script and it worked like a charm, see following screenshot for confirmation. Make sure you run the whole script, so that parent table is created first.