IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_NAME(OBJECT_ID)= 'EST_PED_VD_PAG_NFE')
BEGIN 

CREATE TABLE DBO.EST_PED_VD_PAG_NFE(
	CD_CTR BIGINT IDENTITY(1,1) NOT NULL,
	CD_EMP INT NULL,
	CD_FILIAL INT NULL,
	CD_PED INT NULL,
	VLR_PAG REAL NULL,
 	CD_TIPO_MOEDA INT NULL,
 CONSTRAINT PK_EST_PED_VD_PAG_NFE PRIMARY KEY CLUSTERED 
(
	CD_CTR 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 EST_PED_VD_PAG_NFE  WITH CHECK ADD  CONSTRAINT FK_EST_PED_VD_PAG_NFE_EST_PED_VD FOREIGN KEY(CD_EMP, CD_FILIAL, CD_PED) REFERENCES EST_PED_VD (CD_EMP, CD_FILIAL, CD_PED)
ALTER TABLE EST_PED_VD_PAG_NFE CHECK CONSTRAINT FK_EST_PED_VD_PAG_NFE_EST_PED_VD

END ; 
