IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB](
	[CD_CTR] [int] IDENTITY(1,1) NOT NULL,
	[CD_CTR_PROC_CPL] [int] NOT NULL,
	[CD_USU] [int] NOT NULL,
	[DT_CAD] [datetime] NOT NULL,
	[NM_PARAMETRO_ORIGEM] [varchar](500) NOT NULL,
	[PERC_VARIACAO] [money] NOT NULL,
	[CD_CTR_DEMANDA_PARAMETRO] [int] NULL,
 CONSTRAINT [PK_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB] PRIMARY KEY CLUSTERED 
(
	[CD_CTR] 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_CPL_DEMANDA_PROC_CPL_LIB] ADD  CONSTRAINT [DF_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_NM_PARAMETRO_ORIGEM]  DEFAULT ('') FOR [NM_PARAMETRO_ORIGEM]

ALTER TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB] ADD  CONSTRAINT [DF_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_PERC_VARIACAO]  DEFAULT ((0)) FOR [PERC_VARIACAO]

ALTER TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB]  WITH NOCHECK ADD  CONSTRAINT [FK_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_EST_PROD_CPL_DEMANDA_PARAMETRO] FOREIGN KEY([CD_CTR_DEMANDA_PARAMETRO])
REFERENCES [dbo].[EST_PROD_CPL_DEMANDA_PARAMETRO] ([CD_CTR])

ALTER TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB] NOCHECK CONSTRAINT [FK_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_EST_PROD_CPL_DEMANDA_PARAMETRO]

ALTER TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_EST_PROD_CPL_DEMANDA_PROC_CPL] FOREIGN KEY([CD_CTR_PROC_CPL])
REFERENCES [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL] ([CD_CTR])

ALTER TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB] CHECK CONSTRAINT [FK_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_EST_PROD_CPL_DEMANDA_PROC_CPL]
END