IF OBJECT_ID('EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE') IS NULL
BEGIN
CREATE TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE](
	[CD_CTR] [int] NOT NULL,
	[CD_CTR_IT] [int] NOT NULL,
	[CD_USU] [int] NOT NULL,
	[TIPO_LIBERACAO] [int] NOT NULL,
	[DT_CAD] [datetime] NOT NULL,
 CONSTRAINT [PK_EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE] PRIMARY KEY CLUSTERED 
(
	[CD_CTR] ASC,
	[CD_CTR_IT] ASC,
	[CD_USU] ASC,
	[TIPO_LIBERACAO] 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_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE] UNIQUE NONCLUSTERED 
(
	[CD_CTR] ASC,
	[CD_CTR_IT] ASC,
	[TIPO_LIBERACAO] 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_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE] ADD  CONSTRAINT [DF_EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE_CD_CTR]  DEFAULT ((0)) FOR [CD_CTR]

ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE] ADD  CONSTRAINT [DF_EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE_CD_CTR_IT]  DEFAULT ((0)) FOR [CD_CTR_IT]

ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE] ADD  CONSTRAINT [DF_EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE_CD_USU]  DEFAULT ((0)) FOR [CD_USU]

ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE] ADD  CONSTRAINT [DF_EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE_TIPO_LIBERACAO]  DEFAULT ((0)) FOR [TIPO_LIBERACAO]

ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE_EST_NF_ENT_DANFE_PROVISORIO_ITENS] FOREIGN KEY([CD_CTR], [CD_CTR_IT])
REFERENCES [dbo].[EST_NF_ENT_DANFE_PROVISORIO_ITENS] ([CD_CTR], [CD_CTR_IT])
ON DELETE CASCADE

ALTER TABLE [dbo].[EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE] CHECK CONSTRAINT [FK_EST_NF_ENT_DANFE_PROVISORIO_ITENS_LIBERACAO_PAINEL_NFE_EST_NF_ENT_DANFE_PROVISORIO_ITENS]
END

