IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE NAME = 'EST_PROD_PRECO_DESC_QTDE_PBM')
BEGIN

CREATE TABLE [dbo].[EST_PROD_PRECO_DESC_QTDE_PBM](
	[CD_EMP] [int] NOT NULL,
	[CD_CONV_PBM] [int] NOT NULL,
	[DS_CONV_PBM] [varchar](50) NOT NULL,
	[CD_USU] [int] NOT NULL,
	[DT_CAD] [datetime] NOT NULL,
	[DT_ULT_ALT] [datetime] NULL,
	[FLAG_FAMILIA] [int] NOT NULL,
 CONSTRAINT [PK_EST_PROD_PRECO_DESC_QTDE_PBM] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC,
	[CD_CONV_PBM] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]

END
GO

IF NOT EXISTS (SELECT * FROM SYS.DEFAULT_CONSTRAINTS WHERE NAME = 'DF_EST_PROD_PRECO_DESC_QTDE_PBM_CD_CONV_PBM')
BEGIN
	ALTER TABLE [dbo].[EST_PROD_PRECO_DESC_QTDE_PBM] ADD  CONSTRAINT [DF_EST_PROD_PRECO_DESC_QTDE_PBM_CD_CONV_PBM]  DEFAULT ((0)) FOR [CD_CONV_PBM]
END
GO

IF NOT EXISTS (SELECT * FROM SYS.DEFAULT_CONSTRAINTS WHERE NAME = 'DF_EST_PROD_PRECO_DESC_QTDE_PBM_DS_CONV_PBM')
BEGIN
	ALTER TABLE [dbo].[EST_PROD_PRECO_DESC_QTDE_PBM] ADD  CONSTRAINT [DF_EST_PROD_PRECO_DESC_QTDE_PBM_DS_CONV_PBM]  DEFAULT ('') FOR [DS_CONV_PBM]
END
GO

IF NOT EXISTS (SELECT * FROM SYS.DEFAULT_CONSTRAINTS WHERE NAME = 'DF_EST_PROD_PRECO_DESC_QTDE_PBM_CD_USU')
BEGIN
	ALTER TABLE [dbo].[EST_PROD_PRECO_DESC_QTDE_PBM] ADD  CONSTRAINT [DF_EST_PROD_PRECO_DESC_QTDE_PBM_CD_USU]  DEFAULT ((0)) FOR [CD_USU]
END
GO

IF NOT EXISTS (SELECT * FROM SYS.DEFAULT_CONSTRAINTS WHERE NAME = 'DF_EST_PROD_PRECO_DESC_QTDE_PBM_FLAG_FAMILIA')
BEGIN
	ALTER TABLE [dbo].[EST_PROD_PRECO_DESC_QTDE_PBM] ADD  CONSTRAINT [DF_EST_PROD_PRECO_DESC_QTDE_PBM_FLAG_FAMILIA]  DEFAULT ((0)) FOR [FLAG_FAMILIA]
END
GO

IF NOT EXISTS (SELECT * FROM SYS.foreign_keys WHERE NAME = 'FK_EST_PROD_PRECO_DESC_QTDE_PBM_RC_CLI_CONV')
BEGIN
	ALTER TABLE [dbo].[EST_PROD_PRECO_DESC_QTDE_PBM]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_PRECO_DESC_QTDE_PBM_RC_CLI_CONV] FOREIGN KEY([CD_EMP], [CD_CONV_PBM])
	REFERENCES [dbo].[RC_CLI_CONV] ([CD_EMP], [CD_CONV])

	ALTER TABLE [dbo].[EST_PROD_PRECO_DESC_QTDE_PBM] CHECK CONSTRAINT [FK_EST_PROD_PRECO_DESC_QTDE_PBM_RC_CLI_CONV]
END
GO
