Quantcast
Channel: MySQL Forums - Microsoft SQL Server
Viewing all articles
Browse latest Browse all 686

I am facing an error while migrating data from sql server 2008 to mysql server (no replies)

$
0
0
ALTER PROCEDURE [dbo].[proc_ltcmigrate_residents]
AS
BEGIN


/*
PersonFriendlyId is ported as NULL.
FacilityId is determined based on the following rules in order
a. If there is a valid facilityid in ltcperson that is taken
b. Check the last bed activity in ltcbedschedule and choose that facility
c. Check the last batch activity and choose that facility in batch
d. default to 1
*/

Insert lee_mig...ltcperson
(
ltcPersonID
,FirstName
,LastName
,PersonFriendlyID
,ApplicableAdmissionDate
,Archived
,ArchivedDate
,ArchivedByUserID
,ProgressNoteDays
,ltcOrganisationID
,oldPersonID
,CreatedBy
,CreatedDate
)
SELECT
P.PersonID
,FirstName
,LastName
,PersonFriendlyID
,ApplicableAdmissionDate
,Archived
,ArchivedDate
,case when ArchivedByUserID=-1 then null else ArchivedByUserID end
,ProgressNoteDays
,COALESCE(case when P.FacilityID>0 then P.FacilityID else null end, LastActiveFacility.FacilityId, (select top 1 FacilityID from ltcbatch b where b.PersonId=P.personid and FacilityID>0 and FacilityID is not null order by BatchID desc), 1)
,OldPersonID
,(select top 1 userid from ltcbatch b where b.PersonId=P.personid and b.UserID<>0 order by BatchID)
,(select top 1 DateCreated from ltcbatch b where b.PersonId=P.PersonID order by BatchID)
FROM ltcPerson P
left join
(
SELECT DISTINCT v.OrgID FacilityId, LBS.PersonID from ltcBedSchedule LBS inner join
(Select Max(ID) ID, PersonID from ltcbedschedule where PersonID>0 and BedPK>0 group by PersonID) MLBS on LBS.ID=MLBS.ID
inner join vwBeds v on v.BedPK=LBS.BedPK
) LastActiveFacility on LastActiveFacility.PersonID=P.PersonID
where exists(select * from ltcBatch b where P.personid=b.personid)


insert lee_mig...ltcbeds
(
BedPK
,RoomID
,PersonID
,BedName
,Status
,DateFrom
,BedGPSX
,BedGPSY
)

select

BedPK
,RoomID
,case when PersonID <=0 then null else PersonID end
,BedName
,Status
,DateFrom
,BedGPSX
,BedGPSY

from ltcbeds


After executing this procedure I get an error
OLE DB provider "MSDASQL" for linked server "lee_mig" returned message "[MySQL][ODBC 5.1 Driver][mysqld-5.5.12]Cannot add or update a child row: a foreign key constraint fails (`ltcdb_prod`.`ltcperson`, CONSTRAINT `fk_ltcperson_ltcuser1` FOREIGN KEY (`ArchivedByUserID`) REFERENCES `ltcuser` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION)".
Msg 7343, Level 16, State 2, Line 1
The OLE DB provider "MSDASQL" for linked server "lee_mig" could not INSERT INTO table "[lee_mig]...[ltcperson]".


To debug the error I executed a query and found that there are some UserID which doesn’t exist in ltcuser. And the UserID is a primary key in ltcuser.

Viewing all articles
Browse latest Browse all 686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>