 
IF  not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_PED_ELTR_DEMANDA_CP]') AND type in (N'U'))
begin
     
	IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_EST_PED_ELTR_DEMANDA_CP_EST_COMPRADOR]') AND parent_object_id = OBJECT_ID(N'[dbo].[EST_PED_ELTR_DEMANDA_CP]'))
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [FK_EST_PED_ELTR_DEMANDA_CP_EST_COMPRADOR]
	 
	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_CD_EMP]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_EMP]
	END

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_CD_CTR_DEMANDA]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_CTR_DEMANDA]
	END 

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_STS_DEMANDA]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_STS_DEMANDA]
	END
	 

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_DS_DEMANDA]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_DS_DEMANDA]
	END
	 

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_CD_COMPRADOR]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_COMPRADOR]
	END

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_TP_PED]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_TP_PED]
	END


	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_FLAG_CONS_FACEAMENTO]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_CONS_FACEAMENTO]
	END

	 IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_FLAG_CONS_EST_CD]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_CONS_EST_CD]
	END

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_FLAG_PERC_ACIMA]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_PERC_ACIMA]
	END

	 

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_FLAG_PARAM_ESPECIAL]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_PARAM_ESPECIAL]
	END

	 

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_PERC_ACIMA]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_PERC_ACIMA]
	END

	 

	IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EST_PED_ELTR_DEMANDA_CP_CD_USU]') AND type = 'D')
	BEGIN
	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] DROP CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_USU]
	END

	 


	/****** Object:  Table [dbo].[EST_PED_ELTR_DEMANDA_CP]    Script Date: 07/31/2013 18:10:21 ******/
	IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_PED_ELTR_DEMANDA_CP]') AND type in (N'U'))
	DROP TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP]
	 


	/****** Object:  Table [dbo].[EST_PED_ELTR_DEMANDA_CP]    Script Date: 07/31/2013 18:10:22 ******/
	SET ANSI_NULLS ON
	 

	SET QUOTED_IDENTIFIER ON
	 

	SET ANSI_PADDING ON
	 

	CREATE TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP](
		[CD_EMP] [int] NOT NULL,
		[CD_CTR_DEMANDA] [int] NOT NULL,
		[DT_REF] [datetime] NOT NULL,
		[STS_DEMANDA] [int] NOT NULL,
		[DS_DEMANDA] [varchar](50) NOT NULL,
		[CD_COMPRADOR] [int] NOT NULL,
		[TP_PED] [int] NOT NULL,
		[FLAG_CONS_FACEAMENTO] [int] NOT NULL,
		[FLAG_CONS_EST_CD] [int] NOT NULL,
		[FLAG_PERC_ACIMA] [int] NOT NULL,
		[FLAG_PARAM_ESPECIAL] [int] NOT NULL,
		[PERC_ACIMA] [money] NOT NULL,
		[CD_USU] [int] NOT NULL,
		[DT_CAD] [datetime] NOT NULL,
	 CONSTRAINT [PK_EST_PED_ELTR_DEMANDA_CP] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_CTR_DEMANDA] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
	) ON [PRIMARY]
	 

	SET ANSI_PADDING OFF
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP]  WITH CHECK ADD  CONSTRAINT [FK_EST_PED_ELTR_DEMANDA_CP_EST_COMPRADOR] FOREIGN KEY([CD_EMP], [CD_COMPRADOR])
	REFERENCES [dbo].[EST_COMPRADOR] ([CD_EMP], [CD_COMPRADOR])
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] CHECK CONSTRAINT [FK_EST_PED_ELTR_DEMANDA_CP_EST_COMPRADOR]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_CTR_DEMANDA]  DEFAULT ((0)) FOR [CD_CTR_DEMANDA]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_STS_DEMANDA]  DEFAULT ((0)) FOR [STS_DEMANDA]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_DS_DEMANDA]  DEFAULT ('') FOR [DS_DEMANDA]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_COMPRADOR]  DEFAULT ((0)) FOR [CD_COMPRADOR] 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_TP_PED]  DEFAULT ((0)) FOR [TP_PED]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_CONS_FACEAMENTO]  DEFAULT ((0)) FOR [FLAG_CONS_FACEAMENTO]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_CONS_EST_CD]  DEFAULT ((0)) FOR [FLAG_CONS_EST_CD]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_PERC_ACIMA]  DEFAULT ((0)) FOR [FLAG_PERC_ACIMA]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_FLAG_PARAM_ESPECIAL]  DEFAULT ((0)) FOR [FLAG_PARAM_ESPECIAL]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_PERC_ACIMA]  DEFAULT ((0)) FOR [PERC_ACIMA]
	 

	ALTER TABLE [dbo].[EST_PED_ELTR_DEMANDA_CP] ADD  CONSTRAINT [DF_EST_PED_ELTR_DEMANDA_CP_CD_USU]  DEFAULT ((0)) FOR [CD_USU]
	 
 
end