IF  NOT EXISTS (SELECT * FROM sys.objects 
					WHERE object_id = OBJECT_ID(N'[dbo].[EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL]') 
					AND type in (N'U')) 
BEGIN
	/****** Object:  Table [dbo].[EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL]    Script Date: 19/12/2015 16:23:42 ******/
	SET ANSI_NULLS ON
	SET QUOTED_IDENTIFIER ON

	CREATE TABLE [dbo].[EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL](
		[CD_EMP] [int] NOT NULL,
		[CD_TOP_SHOW] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_FABRIC] [int] NOT NULL,
		[DT_INI_REF] [datetime] NOT NULL,
		[DT_FIM_REF] [datetime] NOT NULL,
		[PERC_META] [money] NOT NULL,
		[QTDE_META] [money] NOT NULL,
		[CD_USU] [int] NOT NULL,
		[DT_CAD] [datetime] NOT NULL,
	 CONSTRAINT [PK_EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL] PRIMARY KEY CLUSTERED 
	(
		[CD_TOP_SHOW] ASC,
		[CD_FABRIC] ASC,
		[CD_FILIAL] ASC,
		[CD_EMP] 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_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL]  WITH CHECK 
		ADD  CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL_EST_TOP_SHOW_CD_TOP_SHOW] FOREIGN KEY([CD_TOP_SHOW],[CD_EMP])
	REFERENCES [dbo].[EST_TOP_SHOW] ([CD_TOP_SHOW],[CD_EMP])
	ON UPDATE CASCADE
	ON DELETE CASCADE

	ALTER TABLE [dbo].[EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL] CHECK CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL_EST_TOP_SHOW_CD_TOP_SHOW]

	ALTER TABLE [dbo].[EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL] 
	 WITH CHECK ADD  CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL_EST_PROD_FABRIC] FOREIGN KEY([CD_FABRIC])
	REFERENCES [dbo].[EST_PROD_FABRIC] ([CD_FABRIC])
	ON UPDATE CASCADE
	ALTER TABLE [dbo].[EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL] CHECK CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_FABRIC_PRC_FILIAL_EST_PROD_FABRIC]


END
