IF EXISTS (SELECT * FROM sys.objects 
					WHERE object_id = OBJECT_ID(N'[dbo].[EST_TOP_SHOW_EST_PROD]') 
					AND type in (N'U')) 
BEGIN
	DROP TABLE [dbo].[EST_TOP_SHOW_EST_PROD]
END

/****** Object:  Table [dbo].[EST_TOP_SHOW_EST_PROD]    Script Date: 19/12/2015 16:23:42 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON

CREATE TABLE [dbo].[EST_TOP_SHOW_EST_PROD](
				[CD_EMP] [int] NOT NULL,
				[CD_TOP_SHOW] [int] NOT NULL,
				[CD_PROD] [int] NOT NULL, 
				[PERC_CRESC] [money] NOT NULL,
				[VLR_VD] [money] NOT NULL,
				[QTD_VD] [money] NOT NULL,
				[CD_USU] [int] NOT NULL,
				[DT_CAD] [datetime] NOT NULL,
				CONSTRAINT [PK_EST_TOP_SHOW_EST_PROD] PRIMARY KEY CLUSTERED 
			(
				[CD_TOP_SHOW] ASC,
				[CD_PROD] 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]  WITH CHECK 
	ADD  CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_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] CHECK CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_EST_TOP_SHOW_CD_TOP_SHOW]

ALTER TABLE [dbo].[EST_TOP_SHOW_EST_PROD]  WITH CHECK ADD  CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_EST_PROD] FOREIGN KEY([CD_EMP], [CD_PROD])
REFERENCES [dbo].[EST_PROD] ([CD_EMP], [CD_PROD])
ON UPDATE CASCADE
ALTER TABLE [dbo].[EST_TOP_SHOW_EST_PROD] CHECK CONSTRAINT [FK_EST_TOP_SHOW_EST_PROD_EST_PROD]
