IF EXISTS (SELECT 1 FROM SYS.TABLES WHERE NAME='LD0P0CUSTOMERDOCUMENTLINKEDDATA')
BEGIN
DROP TABLE LD0P0CUSTOMERDOCUMENTLINKEDDATA
END
;
IF EXISTS (SELECT 1 FROM SYS.VIEWS WHERE NAME='LD0V0CUSTOMERDOCUMENTLINKEDDATA')
BEGIN
DROP VIEW LD0V0CUSTOMERDOCUMENTLINKEDDATA
END
;

CREATE TABLE LD0P0CUSTOMERDOCUMENTLINKEDDATA
(
ID	INT IDENTITY(1,1) NOT NULL,
CUSTOMERDOCUMENTID	INT NOT NULL,
PROCESSID	INT NOT NULL,
ENCOUNTERID	 VARCHAR(100) NOT NULL,
)
;

ALTER TABLE LD0P0CUSTOMERDOCUMENTLINKEDDATA  WITH CHECK ADD  CONSTRAINT LD0P0CUSTOMERDOCUMENTLINKEDDATA_FK FOREIGN KEY(CUSTOMERDOCUMENTID)
REFERENCES LD0P0CUSTOMERDOCUMENT (ID)
;


CREATE VIEW LD0V0CUSTOMERDOCUMENTLINKEDDATA AS 
SELECT * FROM LD0P0CUSTOMERDOCUMENTLINKEDDATA
;
