IF OBJECT_ID('EST_PROD_TBL_COMIS_EST_MC_QTDE') IS NULL
BEGIN 
CREATE TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE](
	[CD_EMP] [int] NOT NULL,
	[CD_TBL_COMIS] [int] NOT NULL,
	[CD_TBL_COMIS_ITEM] [int] NOT NULL,
	[CD_MC] [int] NOT NULL,
	[QTDE_PROD] [money] NOT NULL,
	[PERC_COMIS] [money] NOT NULL,
 CONSTRAINT [PK_EST_PROD_TBL_COMIS_EST_MC_QTDE] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC,
	[CD_TBL_COMIS] ASC,
	[CD_TBL_COMIS_ITEM] 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_COMIS_EST_MC_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_MC_QTDE_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_MC_QTDE_CD_TBL_COMIS]  DEFAULT ((0)) FOR [CD_TBL_COMIS]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_MC_QTDE_CD_TBL_COMIS_ITEM]  DEFAULT ((0)) FOR [CD_TBL_COMIS_ITEM]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_MC_QTDE_CD_MC]  DEFAULT ((0)) FOR [CD_MC]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_MC_QTDE_QTDE_PROD]  DEFAULT ((0)) FOR [QTDE_PROD]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_MC_QTDE_PERC_COMIS]  DEFAULT ((0)) FOR [PERC_COMIS]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_MC_QTDE_EST_PROD] FOREIGN KEY([CD_EMP], [CD_MC])
REFERENCES [dbo].[EST_MC] ([CD_EMP], [CD_MC])

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE] CHECK CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_MC_QTDE_EST_PROD]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_MC_QTDE_EST_PROD_TBL_COMIS] FOREIGN KEY([CD_EMP], [CD_TBL_COMIS])
REFERENCES [dbo].[EST_PROD_TBL_COMIS] ([CD_EMP], [CD_TBL_COMIS])

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_MC_QTDE] CHECK CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_MC_QTDE_EST_PROD_TBL_COMIS]
END