IF NOT EXISTS(
	SELECT 
		1
	FROM 
		 sys.tables 
	WHERE 
		NAME = 'RC_CLI_CONV_EST_PROD_TBL_DESC' )
BEGIN

	/****** Object:  Table [dbo].[RC_CLI_CONV_EST_PROD_TBL_DESC]    Script Date: 04/09/2012 15:15:22 ******/
	SET ANSI_NULLS ON

	SET QUOTED_IDENTIFIER ON

	CREATE TABLE [dbo].[RC_CLI_CONV_EST_PROD_TBL_DESC](
		[CD_EMP] [int] NOT NULL,
		[CD_CONV] [int] NOT NULL,
		[CD_TBL_DESC] [int] NOT NULL,
		[CD_PLANO_VENDA] [int] NOT NULL,
	 CONSTRAINT [PK_RC_CLI_CONV_EST_PROD_TBL_DESC] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_CONV] ASC,
		[CD_TBL_DESC] ASC,
		[CD_PLANO_VENDA] 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].[RC_CLI_CONV_EST_PROD_TBL_DESC]  WITH CHECK ADD  CONSTRAINT [FK_RC_CLI_CONV_EST_PROD_TBL_DESC_EST_PROD_TBL_DESC] FOREIGN KEY([CD_EMP], [CD_TBL_DESC])
	REFERENCES [dbo].[EST_PROD_TBL_DESC] ([CD_EMP], [CD_TBL_DESC])
	ON UPDATE CASCADE

	ALTER TABLE [dbo].[RC_CLI_CONV_EST_PROD_TBL_DESC] CHECK CONSTRAINT [FK_RC_CLI_CONV_EST_PROD_TBL_DESC_EST_PROD_TBL_DESC]

	ALTER TABLE [dbo].[RC_CLI_CONV_EST_PROD_TBL_DESC]  WITH CHECK ADD  CONSTRAINT [FK_RC_CLI_CONV_EST_PROD_TBL_DESC_GBL_PLANO_VENDA] FOREIGN KEY([CD_PLANO_VENDA])
	REFERENCES [dbo].[GLB_PLANO_VENDA] ([CD_PLANO_VENDA])
	ON UPDATE CASCADE

	ALTER TABLE [dbo].[RC_CLI_CONV_EST_PROD_TBL_DESC] CHECK CONSTRAINT [FK_RC_CLI_CONV_EST_PROD_TBL_DESC_GBL_PLANO_VENDA]

	ALTER TABLE [dbo].[RC_CLI_CONV_EST_PROD_TBL_DESC]  WITH CHECK ADD  CONSTRAINT [FK_RC_CLI_CONV_EST_PROD_TBL_DESC_RC_CLI_CONV] FOREIGN KEY([CD_EMP], [CD_CONV])
	REFERENCES [dbo].[RC_CLI_CONV] ([CD_EMP], [CD_CONV])
	ON UPDATE CASCADE
	ON DELETE CASCADE

	ALTER TABLE [dbo].[RC_CLI_CONV_EST_PROD_TBL_DESC] CHECK CONSTRAINT [FK_RC_CLI_CONV_EST_PROD_TBL_DESC_RC_CLI_CONV]

END

