/*
  MS SQL Server script to revert referral details list changes
  Moulya 15 March 2019

*/

delete from referral_details where item_index != 0
alter table carespell add REFERRAL_ID int null
go

update cs
set cs.REFERRAL_ID = rd.REFERRAL_ID
from REFERRAL_DETAILS rd
       inner join carespell cs on cs.carespell_id = rd.carespell_id

go
Alter table referral_details drop  constraint [FK_9q0ap458nr66uxy7pkd7ag3sv]
go
alter table referral_details drop column carespell_id;
alter table referral_details drop column item_index;
go

alter table carespell  with check add  constraint [FK_carespell_referral_id] FOREIGN KEY(REFERRAL_ID)
 references referral_details (REFERRAL_ID)
go

alter table carespell check constraint [FK_carespell_referral_id]
go
