IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES
			 WHERE TABLE_NAME='EST_NF_ENT_EST_NF_ENT_CPL')
BEGIN
    CREATE TABLE [dbo].[EST_NF_ENT_EST_NF_ENT_CPL](
	    [CD_EMP] [int] NOT NULL,
	    [CD_FILIAL] [int] NOT NULL,
	    [CD_NF] [int] NOT NULL,
	    [CD_NF_REF] [int] NOT NULL,
	CONSTRAINT [PK_EST_NF_ENT_EST_NF_ENT_CPL] PRIMARY KEY CLUSTERED 
    (
	    [CD_EMP] ASC,
	    [CD_FILIAL] ASC,
	    [CD_NF] ASC,
	    [CD_NF_REF] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
    ) ON [PRIMARY]

    ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_ENT_CPL]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_EST_NF_ENT_CPL_EST_NF_ENT] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_NF])
    REFERENCES [dbo].[EST_NF_ENT] ([CD_EMP], [CD_FILIAL], [CD_NF])
    ON UPDATE CASCADE
    ON DELETE CASCADE 

    ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_ENT_CPL] CHECK CONSTRAINT [FK_EST_NF_ENT_EST_NF_ENT_CPL_EST_NF_ENT]
 

    ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_ENT_CPL]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_EST_NF_ENT_CPL_EST_NF_ENT_ORIG] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_NF_REF])
    REFERENCES [dbo].[EST_NF_ENT] ([CD_EMP], [CD_FILIAL], [CD_NF])
 

    ALTER TABLE [dbo].[EST_NF_ENT_EST_NF_ENT_CPL] CHECK CONSTRAINT [FK_EST_NF_ENT_EST_NF_ENT_CPL_EST_NF_ENT_ORIG]
END


