IF  NOT EXISTS (SELECT * FROM sys.objects 
					WHERE object_id = OBJECT_ID(N'EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL') 
					AND type in (N'U')) 
BEGIN
CREATE TABLE [dbo].[EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL](
	[CD_CTR] [int] NOT NULL,
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[DT_CAD] [datetime] NOT NULL,
 CONSTRAINT [PK_EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL] PRIMARY KEY CLUSTERED 
(
	[CD_CTR] ASC,
	[CD_EMP] ASC,
	[CD_FILIAL] 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_CPL_VD_LOTE_PROC_PRC_FILIAL] ADD  CONSTRAINT [DF_EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL_DT_CAD]  DEFAULT (getdate()) FOR [DT_CAD]

ALTER TABLE [dbo].[EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL_EST_PROD_CPL_VD_LOTE_PROC_PENDENTE] FOREIGN KEY([CD_CTR])
REFERENCES [dbo].[EST_PROD_CPL_VD_LOTE_PROC_PENDENTE] ([CD_CTR])
ON UPDATE CASCADE
ON DELETE CASCADE

ALTER TABLE [dbo].[EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL] CHECK CONSTRAINT [FK_EST_PROD_CPL_VD_LOTE_PROC_PRC_FILIAL_EST_PROD_CPL_VD_LOTE_PROC_PENDENTE]
END

