IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE NAME = 'EST_NF_SAI_EST_PED_VD')
Begin
CREATE TABLE [dbo].[EST_NF_SAI_EST_PED_VD](
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_NF] [int] NOT NULL,
	[CD_PED] [int] NOT NULL,
 CONSTRAINT [PK_EST_NF_SAI_EST_PED_VD] PRIMARY KEY CLUSTERED 
(
	[CD_EMP] ASC,
	[CD_FILIAL] ASC,
	[CD_NF] ASC,
	[CD_PED] 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]


ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD] ADD  CONSTRAINT [DF_EST_NF_SAI_EST_PED_VD_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD] ADD  CONSTRAINT [DF_EST_NF_SAI_EST_PED_VD_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD] ADD  CONSTRAINT [DF_EST_NF_SAI_EST_PED_VD_CD_NF]  DEFAULT ((0)) FOR [CD_NF]

ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD] ADD  CONSTRAINT [DF_EST_NF_SAI_EST_PED_VD_CD_PED]  DEFAULT ((0)) FOR [CD_PED]

ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_SAI_EST_PED_VD_EST_NF_SAI] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_NF])
REFERENCES [dbo].[EST_NF_SAI] ([CD_EMP], [CD_FILIAL], [CD_NF])

ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD] CHECK CONSTRAINT [FK_EST_NF_SAI_EST_PED_VD_EST_NF_SAI]

ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_SAI_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])

ALTER TABLE [dbo].[EST_NF_SAI_EST_PED_VD] CHECK CONSTRAINT [FK_EST_NF_SAI_EST_PED_VD_EST_PED_VD]
end