IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_EST_CONTINGENCIA_GLB_USU]') AND parent_object_id = OBJECT_ID(N'[dbo].[EST_CONTINGENCIA]'))
BEGIN
CREATE TABLE [dbo].[EST_CONTINGENCIA](
	[CD_CTR] [int] NOT NULL,
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[STATUS_CONTINGENCIA] [int] NOT NULL,
	[DT_CONTINGENCIA] [datetime] NOT NULL,
	[CD_USU] [int] NOT NULL,
 CONSTRAINT [PK_EST_CONTINGENCIA] 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_CONTINGENCIA]  WITH CHECK ADD  CONSTRAINT [FK_EST_CONTINGENCIA_GLB_USU] FOREIGN KEY([CD_USU])
REFERENCES [dbo].[GLB_USU] ([CD_USU])


ALTER TABLE [dbo].[EST_CONTINGENCIA] CHECK CONSTRAINT [FK_EST_CONTINGENCIA_GLB_USU]




ALTER TABLE [dbo].[EST_CONTINGENCIA]  WITH CHECK ADD  CONSTRAINT [FK_EST_CONTINGENCIA_PRC_EMP] FOREIGN KEY([CD_EMP])
REFERENCES [dbo].[PRC_EMP] ([CD_EMP])


ALTER TABLE [dbo].[EST_CONTINGENCIA] CHECK CONSTRAINT [FK_EST_CONTINGENCIA_PRC_EMP]


ALTER TABLE [dbo].[EST_CONTINGENCIA] ADD  CONSTRAINT [DF_EST_CONTINGENCIA_DT_CONTINGENCIA]  DEFAULT (getdate()) FOR [DT_CONTINGENCIA]

END