IF	OBJECT_ID('EST_PROD_TBL_FIDEL_PRC_FILIAL') IS NULL
begin
CREATE TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL](
	[CD_EMP] [int] NOT NULL,
	[CD_TBL_FIDEL] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[QTDE_PONTO] [money] NOT NULL,
 CONSTRAINT [PK_EST_PROD_TBL_FIDEL_PRC_FILIAL] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC,
	[CD_TBL_FIDEL] 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_TBL_FIDEL_PRC_FILIAL] ADD  CONSTRAINT [DF_EST_PROD_TBL_FIDEL_PRC_FILIAL_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL] ADD  CONSTRAINT [DF_EST_PROD_TBL_FIDEL_PRC_FILIAL_CD_TBL_FIDEL]  DEFAULT ((0)) FOR [CD_TBL_FIDEL]

ALTER TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL] ADD  CONSTRAINT [DF_EST_PROD_TBL_FIDEL_PRC_FILIAL_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

ALTER TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL] ADD  CONSTRAINT [DF_EST_PROD_TBL_FIDEL_PRC_FILIAL_QTDE_PONTO]  DEFAULT ((0)) FOR [QTDE_PONTO]

ALTER TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TBL_FIDEL_PRC_FILIAL_EST_PROD_TBL_FIDEL] FOREIGN KEY([CD_EMP], [CD_TBL_FIDEL])
REFERENCES [dbo].[EST_PROD_TBL_FIDEL] ([CD_EMP], [CD_TBL_FIDEL])

ALTER TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL] CHECK CONSTRAINT [FK_EST_PROD_TBL_FIDEL_PRC_FILIAL_EST_PROD_TBL_FIDEL]

ALTER TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TBL_FIDEL_PRC_FILIAL_PRC_FILIAL] FOREIGN KEY([CD_EMP], [CD_FILIAL])
REFERENCES [dbo].[PRC_FILIAL] ([CD_EMP], [CD_FILIAL])

ALTER TABLE [dbo].[EST_PROD_TBL_FIDEL_PRC_FILIAL] CHECK CONSTRAINT [FK_EST_PROD_TBL_FIDEL_PRC_FILIAL_PRC_FILIAL]
end

