This query responds to a problem with an import from Family Historian via FTM-flavoured GEDCOM reported by Stewartrb in the RootsMagic Forums thread GEDCOM import with media. The images linked to the person in Family Historian were ultimately tagged as such in RootsMagic but none was marked as the Primary photo. Consequently, none showed on the main screen nor in reports other than Scrapbooks. This query sets the last-tagged image-type media file among those that have been tagged to a person as that person’s Primary photo, when none of the tags for that person have been so checked. It could be readily modified to be the first tag added to the person rather than the last.
-- MediaTags-SetPrimaryForPersons.sql
/* 2013-09-23 ve3meo
Sets the last mediatag as the Primary photo for a person with 1 or more tags for image-type media, none of which are so checked.
Rev 2026-08-03 Tom Holden
Updated to replace old SQLite behaviour from 2013: sorting rows in an inner subquery (ORDER BY ML.OwnerID, ML.IsPrimary) and
expecting GROUP BY OwnerID in the outer query to return the last ordered row. Not guaranteed by the current SQLite engine.
Now uses aggregate functions which is simpler, faster and more reliable code.
Tested on RM11 database and should be backward compatible to RM4.
*/
UPDATE MediaLinkTable
SET IsPrimary = 1
WHERE LinkID IN (
SELECT MAX(ML.LinkID) -- latest mediatag for Person. Change to MIN(ML.LinkID)for the earliest tag to be set Primary
FROM MediaLinkTable ML -- mediatag links
INNER JOIN MultiMediaTable MM -- links to media files
ON ML.MediaID = MM.MediaID -- relates mediatags to media items
WHERE ML.OwnerType = 0 -- Person
AND MM.MediaType = 1 -- Image
GROUP BY ML.OwnerID -- PersonID
HAVING MAX(ML.IsPrimary) = 0 -- Only persons with NO primary photo assigned.
)
;
Added version that sets the first mediatag as Primary when none of the tags for a person are marked as such.
On the RM Community page, I posted the following on a page where users are discussing problems with TreeShare. https://community.rootsmagic.com/t/reset-treeshare-tool/13315
I am following all of this with great interest. Basically I had a large tree over 500,000 people that had been linked to treeshare for several years. For reasons I can’t remember, I decided to disconnect my tree and re-upload it. I wish I had never done this. I have not successfully uploaded the tree; it gets stuck while uploading media … sometimes early, sometimes at 99%. I have not gotten past that poinr so unsure if I have a similar problem with sources. However I noticed one thing that no one else has mentioned. I ran Media – Set Primary Photo for Persons #media #update several months ago and just noticed that some people have multiple media checked as primary photos. Hmmmm….. If I remove all the checks and attempt to check multiples, RM does not allow it, as it should. I am wondering if this might be the reason my tree freezes during the media upload? Does anyone else have multiple pictures checked as primary? I am going to copy/paste this post onto the SQLite Tools for RM page. Maybe all I need is a new script to uncheck all media.
I just saw your comment here but your link to the RootsMagic Community topic on Resetting TreeShare has no comment from you. If you want to unset all Primary images for a Person, this should work:
UPDATE MediaLinkTable
SET IsPrimary = 0
WHERE
OwnerType=0
;
Remove the WHERE clause to eliminate any other Primary settings for all types of media and for all tags, not just to Persons.
Thank you Tom, sorry for the error about my posting. Sometimes online forums are confusing to me.
To Tom Holden: I have been recommended to try your fix as outlined above. But do you know if it work on RM 11? Your message only specifies up to RM10/
Also – could you give me idiot’s guide as to how I insert the program instructions above into my RootsMagic program files.
Hi Peggy, I have just now revised the query to take advantage of an improvement is SQLite syntax (or my improved understanding of it) since the script was first developed. It is compatible with RM11.
You do not insert the SQLite script into the RM application. See the Learn item on the menu bar at the top of this website. You do need to be competent at managing files in your computer’s operating system and have some aptitude for learning the computer skills needed to install and use a SQLite manager safely on your database file (either a copy of the file or the original provided it has a backup to which you can fall back if something did not work out as expected).