IF NOT EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI')
begin
CREATE TABLE [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI](
	[CD_CTR_MINUTA] [int] NOT NULL,
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_NF] [int] NOT NULL,
 CONSTRAINT [PK_EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI] PRIMARY KEY CLUSTERED 
(
	[CD_CTR_MINUTA] ASC,
	[CD_EMP] ASC,
	[CD_FILIAL] ASC,
	[CD_NF] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


ALTER TABLE [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI] ADD  CONSTRAINT [DF_EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI_CD_CTR_MINUTA]  DEFAULT ((0)) FOR [CD_CTR_MINUTA]

ALTER TABLE [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI] ADD  CONSTRAINT [DF_EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI] ADD  CONSTRAINT [DF_EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

ALTER TABLE [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI] ADD  CONSTRAINT [DF_EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI_CD_NF]  DEFAULT ((0)) FOR [CD_NF]

ALTER TABLE [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI_EST_PROD_TRANSF_MINUTA_ENTREGA] FOREIGN KEY([CD_CTR_MINUTA])
REFERENCES [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA] ([CD_CTR_MINUTA])

ALTER TABLE [dbo].[EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI] CHECK CONSTRAINT [FK_EST_PROD_TRANSF_MINUTA_ENTREGA_CPL_EST_NF_SAI_EST_PROD_TRANSF_MINUTA_ENTREGA]
end
