IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO](
	[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,
	[CD_CTR_DEMANDA_PARAMETRO] [int] NULL,
 CONSTRAINT [PK_EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO] 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],
 CONSTRAINT [IX_EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO] UNIQUE NONCLUSTERED 
(
	[CD_CTR_DEMANDA_PARAMETRO] 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_BLOQUEIO] ADD  CONSTRAINT [DF_EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO_CD_CTR_PROC_CPL]  DEFAULT ((0)) FOR [CD_CTR_PROC_CPL]

ALTER TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO] ADD  CONSTRAINT [DF_EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO_CD_USU]  DEFAULT ((0)) FOR [CD_USU]

ALTER TABLE [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO]  WITH CHECK ADD  CONSTRAINT [FK_EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO_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_BLOQUEIO] CHECK CONSTRAINT [FK_EST_PROD_CPL_DEMANDA_PROC_CPL_BLOQUEIO_EST_PROD_CPL_DEMANDA_PROC_CPL]
end
