IF  NOT EXISTS (SELECT * FROM sys.objects 
					WHERE object_id = OBJECT_ID(N'[dbo].[TELE_ORC_EST_PED_VD]') 
					AND type in (N'U')) 
BEGIN
	/****** Object:  Table [dbo].[TELE_ORC_EST_PED_VD]    Script Date: 19/12/2015 15:22:40 ******/
	SET ANSI_NULLS ON  
	SET QUOTED_IDENTIFIER ON 

	CREATE TABLE [dbo].[TELE_ORC_EST_PED_VD](
		[CD_ORC] [int] NOT NULL,
		[CD_EMP] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_PED] [int] NOT NULL,
	 CONSTRAINT [PK_TELE_ORC_EST_PED_VD] PRIMARY KEY CLUSTERED 
	(	[CD_ORC] ASC, 
		[CD_EMP] ASC, 
		[CD_FILIAL] ASC, 
		[CD_PED] 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].[TELE_ORC_EST_PED_VD]  WITH CHECK ADD  CONSTRAINT [FK_TELE_ORC_EST_PED_VD_TELE_ORC] 
		FOREIGN KEY([CD_ORC]) REFERENCES [dbo].[TELE_ORC] ([CD_ORC])
	ON DELETE CASCADE
		ALTER TABLE [dbo].[TELE_ORC_EST_PED_VD] CHECK CONSTRAINT [FK_TELE_ORC_EST_PED_VD_TELE_ORC] 

	ALTER TABLE [dbo].[TELE_ORC_EST_PED_VD]  WITH CHECK ADD  CONSTRAINT [FK_TELE_ORC_EST_PED_VD_EST_PED_VD] 
		FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_PED]) REFERENCES [dbo].[EST_PED_VD] ([CD_EMP], [CD_FILIAL], [CD_PED])
	ON DELETE CASCADE
		ALTER TABLE [dbo].[TELE_ORC_EST_PED_VD] CHECK CONSTRAINT [FK_TELE_ORC_EST_PED_VD_EST_PED_VD]
END