IF OBJECT_ID('GLB_USU_FORN') IS NOT NULL
	GOTO FINAL

CREATE TABLE [dbo].[GLB_USU_FORN](
	[CD_EMP] [int] NOT NULL,
	[CD_USU_FORN] [int] NOT NULL IDENTITY,
	[NM_USU_FORN] [varchar](50) NOT NULL,
	[SENHA] [varchar](100) NOT NULL,
	[SIT] [int] NOT NULL,
	[MASTER] [int] NULL,
	[ATIVO] [int] NULL,
	[CD_USU_FORN_CAD] [int] NULL,
	[DT_CAD] [datetime] NULL,
	[DT_ULT_ALT] [datetime] NULL,
	[DT_SENHA_ALTERADA] [datetime] NULL,
	[CD_FORN] [INT] NOT NULL
 CONSTRAINT [PK_GLB_USU_FORN] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC,
	[CD_USU_FORN] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]


FINAL:
GO


IF OBJECT_ID('DF_GLB_USU_FORN_NM_USU_FORN') IS NOT NULL
	GOTO FINAL

ALTER TABLE [dbo].[GLB_USU_FORN] ADD  CONSTRAINT [DF_GLB_USU_FORN_NM_USU_FORN]  DEFAULT ('') FOR [NM_USU_FORN]
FINAL:
GO


IF OBJECT_ID('DF_GLB_USU_FORN_SENHA') IS NOT NULL
	GOTO FINAL

ALTER TABLE [dbo].[GLB_USU_FORN] ADD  CONSTRAINT [DF_GLB_USU_FORN_SENHA]  DEFAULT ('') FOR [SENHA]
FINAL:
GO


IF OBJECT_ID('DF_GLB_USU_FORN_SIT') IS NOT NULL
	GOTO FINAL

ALTER TABLE [dbo].[GLB_USU_FORN] ADD  CONSTRAINT [DF_GLB_USU_FORN_SIT]  DEFAULT ((0)) FOR [SIT]
FINAL:
GO


IF OBJECT_ID('DF_GLB_USU_FORN_DT_SENHA_ALTERADA') IS NOT NULL
	GOTO FINAL

ALTER TABLE [dbo].[GLB_USU_FORN] ADD  CONSTRAINT [DF_GLB_USU_FORN_DT_SENHA_ALTERADA]  DEFAULT (getdate()) FOR [DT_SENHA_ALTERADA]
FINAL:
GO


IF OBJECT_ID('DF_GLB_USU_FORN_CD_FORN') IS NOT NULL
	GOTO FINAL

ALTER TABLE [dbo].[GLB_USU_FORN] ADD  CONSTRAINT [DF_GLB_USU_FORN_CD_FORN]  DEFAULT (0) FOR [CD_FORN]
FINAL:
GO

IF OBJECT_ID('FK_GLB_USU_FORN_PG_FORN_CD_FORN') IS NOT NULL
	GOTO FINAL

ALTER TABLE [dbo].[GLB_USU_FORN] ADD CONSTRAINT [FK_GLB_USU_FORN_PG_FORN_CD_FORN] FOREIGN KEY ([CD_EMP],[CD_FORN]) REFERENCES PG_FORN ([CD_EMP],[CD_FORN])
FINAL:
GO

