
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TELE_ORC_PBM]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[TELE_ORC_PBM](
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_ORC] [int] NOT NULL,
	[ID_TERMINAL] [varchar](50) NOT NULL,
	[NSU_REQ] [int] NOT NULL,
	[NUMERO_SESSAO] [varchar](50) NOT NULL,
	[CD_PROJETO] [int] NOT NULL,
	[CGC_CPF] VARCHAR(20) NOT NULL,
	CONSTRAINT PK_TELE_ORC_PBM PRIMARY KEY (CD_EMP,CD_FILIAL,CD_ORC)
	) ON [PRIMARY];

ALTER TABLE [dbo].[TELE_ORC_PBM]  WITH CHECK ADD  CONSTRAINT [FK_TELE_ORC_PBM_EST_ORC] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_ORC])
REFERENCES [dbo].[EST_ORC] ([CD_EMP], [CD_FILIAL], [CD_ORC])

ALTER TABLE [dbo].[TELE_ORC_PBM] CHECK CONSTRAINT [FK_TELE_ORC_PBM_EST_ORC];

END
