/****** Object:  Table [dbo].[EST_PED_CP_AGENDA_ENTREGA]    Script Date: 03/31/2014 15:29:12 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_PED_CP_AGENDA_ENTREGA]') AND type in (N'U'))
DROP TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] 
GO
GO
GO
CREATE TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA](
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_PED] [int] NOT NULL,
	[DT_AGENDA_ENTREGA] [datetime] NOT NULL,
	[CD_USU] [int] NOT NULL,
	[QTDE_VOLUMES_AGENDADO] [int] NOT NULL,
	[QTDE_VOLUMES_RECEBIDOS] [int] NOT NULL,
	[ORDEM] [int] NOT NULL,
	[DT_AGENDA_SOLICITACAO] [datetime] NOT NULL,
	[DT_AGENDA_RESPOSTA] [datetime] NULL,
	[NR_NF] [int] NOT NULL,
	[OBS] [varchar](250) NOT NULL,
	[DT_EMI_NF] [datetime] NOT NULL,
	[CD_FORN] [int] NOT NULL,
 CONSTRAINT [PK_EST_PED_CP_AGENDA_ENTREGA] PRIMARY KEY CLUSTERED 
(
	[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].[EST_PED_CP_AGENDA_ENTREGA]  WITH CHECK ADD  CONSTRAINT [FK_EST_PED_CP_AGENDA_ENTREGA_EST_PED_CP] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_PED])
REFERENCES [dbo].[EST_PED_CP] ([CD_EMP], [CD_FILIAL], [CD_PED])
ON DELETE CASCADE

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] CHECK CONSTRAINT [FK_EST_PED_CP_AGENDA_ENTREGA_EST_PED_CP]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_CD_PED]  DEFAULT ((0)) FOR [CD_PED]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_CD_USU]  DEFAULT ((0)) FOR [CD_USU]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_QTDE_VOLUMES_AGENDADO]  DEFAULT ((0)) FOR [QTDE_VOLUMES_AGENDADO]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_QTDE_VOLUMES_RECEBIDOS]  DEFAULT ((0)) FOR [QTDE_VOLUMES_RECEBIDOS]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_ORDEM]  DEFAULT ((0)) FOR [ORDEM]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_DT_AGENDA_SOLICITACAO]  DEFAULT (getdate()) FOR [DT_AGENDA_SOLICITACAO]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_NR_NF]  DEFAULT ((0)) FOR [NR_NF]

ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_OBS]  DEFAULT ('') FOR [OBS]


ALTER TABLE [dbo].[EST_PED_CP_AGENDA_ENTREGA] ADD  CONSTRAINT [DF_EST_PED_CP_AGENDA_ENTREGA_CD_FORN]  DEFAULT ((0)) FOR [CD_FORN]