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

BEGIN
CREATE TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP](
	[CD_EMP] [int]  NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_VD] [int] NOT NULL,
	[CD_IMP] [int] NOT NULL,
	[CD_PROD] [int] NOT NULL,
	[CD_IT] [int] NOT NULL,
	[DT_CAD] [DATETIME] NOT NULL,
 CONSTRAINT [PK_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC,
	[CD_FILIAL] ASC,
	[CD_VD] ASC,
	[CD_IMP] ASC,
	[CD_PROD] ASC,
	[CD_IT] 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].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] ADD  CONSTRAINT [DF_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] ADD  CONSTRAINT [DF_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

ALTER TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] ADD  CONSTRAINT [DF_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_CD_VD]  DEFAULT ((0)) FOR [CD_VD]

ALTER TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] ADD  CONSTRAINT [DF_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_CD_IMP]  DEFAULT ((0)) FOR [CD_IMP]

ALTER TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] ADD  CONSTRAINT [DF_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_CD_PROD]  DEFAULT ((0)) FOR [CD_PROD]

ALTER TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] ADD  CONSTRAINT [DF_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_CD_IT]  DEFAULT ((0)) FOR [CD_IT]

ALTER TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP] ADD  CONSTRAINT [DF_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_DT_CAD]  DEFAULT (GETDATE()) FOR [DT_CAD]

ALTER TABLE [dbo].[PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP]  WITH CHECK ADD  CONSTRAINT [FK_PDV_VD_DEV_EST_PROD_IMP_PEND_RESHOP_PDV_VD_DEV_EST_PROD_IMP] 
	FOREIGN KEY([CD_EMP], [CD_FILIAL],[CD_VD], [CD_IMP], [CD_PROD],[CD_IT])
REFERENCES [dbo].[PDV_VD_DEV_EST_PROD_IMP] ([CD_EMP], [CD_FILIAL],[CD_VD], [CD_IMP], [CD_PROD],[CD_IT])
ON DELETE CASCADE ON UPDATE CASCADE

END
