IF OBJECT_ID('EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE') IS NULL
BEGIN 
CREATE TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE](
	[CD_EMP] [int] NOT NULL,
	[CD_TBL_COMIS] [int] NOT NULL,
	[CD_TBL_COMIS_ITEM] [int] NOT NULL,
	[CD_ARV_MERC_LINHA] [int] NOT NULL,
	[QTDE_PROD] [money] NOT NULL,
	[PERC_COMIS] [money] NOT NULL,
 CONSTRAINT [PK_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_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_ARV_MERC_LINHA_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_CD_TBL_COMIS]  DEFAULT ((0)) FOR [CD_TBL_COMIS]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_CD_TBL_COMIS_ITEM]  DEFAULT ((0)) FOR [CD_TBL_COMIS_ITEM]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_CD_ARV_MERC_LINHA]  DEFAULT ((0)) FOR [CD_ARV_MERC_LINHA]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_QTDE_PROD]  DEFAULT ((0)) FOR [QTDE_PROD]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE] ADD  CONSTRAINT [DF_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_PERC_COMIS]  DEFAULT ((0)) FOR [PERC_COMIS]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_EST_PROD] FOREIGN KEY([CD_EMP], [CD_ARV_MERC_LINHA])
REFERENCES [dbo].[EST_ARV_MERC_LINHA] ([CD_EMP], [CD_ARV_MERC_LINHA])

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE] CHECK CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_EST_PROD]

ALTER TABLE [dbo].[EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_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_ARV_MERC_LINHA_QTDE] CHECK CONSTRAINT [FK_EST_PROD_TBL_COMIS_EST_ARV_MERC_LINHA_QTDE_EST_PROD_TBL_COMIS]
END