delete from dbo.cf_Part; -- truncate all data
alter table dbo.cf_Part add [extPartId] int null;

--

delete from dbo.cf_Department; -- truncate all data
-- alter table dbo.cf_Department add [extDepartmentId] int null; -- немає ід-шок в даних для імпору, імпортуються по іменах

--

delete from dbo.cf_Process; -- truncate all data
-- alter table dbo.cf_Process add [extProcessId] int null; -- немає ід-шок в даних для імпору, імпортуються по іменах

--

delete from dbo.cf_DepartmentAndProcessSorter; -- truncate all data

alter table dbo.cf_DepartmentAndProcessSorter
add foreign key (departmentId)
references dbo.cf_department (id)
on delete cascade
on update no action;

alter table dbo.cf_DepartmentAndProcessSorter
add foreign key (processId)
references dbo.cf_Process (id)
on delete cascade
on update no action;

--

delete from cf_Process2User; -- truncate all data

alter table dbo.cf_Process2User
add foreign key (processId)
references dbo.cf_Process (id)
on delete cascade
on update no action;

alter table dbo.cf_Process2User
add foreign key (userId)
references dbo.cf_User (id)
on delete cascade
on update no action;

--

delete from dbo.cf_FormElementPropertyValue; -- truncate all data

alter table dbo.cf_FormElementPropertyValue
add foreign key (elementId)
references dbo.cf_FormElement (id)
on delete cascade
on update no action ;

alter table dbo.cf_FormElementPropertyValue
add foreign key (propertyId)
references dbo.cf_FormElementProperty (id)
on delete cascade
on update no action ;

--

-- в cf_FormSubmission нічого не вставляється
-- alter table dbo.cf_FormSubmissionValue
-- add foreign key (submissionId)
-- references dbo.cf_FormSubmission (id)
-- on delete cascade
-- on update no action ;

alter table dbo.cf_FormSubmissionValue
add foreign key (elementId)
references dbo.cf_FormElement (id)
on delete cascade
on update no action ;

--
-- вже доданий
-- alter table dbo.cf_Part2Process
-- add foreign key (partId)
-- references dbo.cf_Part (id)
-- on delete cascade
-- on update no action ;

alter table dbo.cf_Part2Process
add foreign key (processId)
references dbo.cf_Process (id)
on delete cascade
on update no action ;

--

alter table dbo.cf_Media
add foreign key (processId)
references dbo.cf_Process (id)
on delete cascade
on update no action ;
