The UPDATE statement conflicted with the FOREIGN KEY
Posted on 2009-05-01
Ive got an issue updating a field in an MS CRM (SQL) database
Basically i have a load of accounts with no primary contact, however, there are multiple contacts for each account....
Set accountbase.[primarycontactid] = dbo.contactbase.[accountid]
Inner Join [contactbase]
on dbo.accountbase.[accountid] = dbo.contactbase.[accountid]
where accountbase.[primarycontactid] is null and dbo.contactbase.fullname is not null and dbo.accountbase.deletionstatecode = 0
Msg 547, Level 16, State 0, Line 1
The UPDATE statement conflicted with the FOREIGN KEY constraint "account_primary_contact". The conflict occurred in database "CRM_MSCRM", table "dbo.ContactBase", column 'ContactId'.
The statement has been terminated.
I just want to pick the first contact availible, how can i modify this query to update the account with only the first contact?