How to migrate User Links / My links from sharepoint 2007 to 2010 using SQL query

Posted by Leszek Polnik | Posted in , , , | Posted on 01:26

0

I have to migrate User links during migration to new SharePoint 2010 farm.
UserLinks table in SQL is pretty simple so i decide to use below SQL script. Remember that you do any changes in SQL db on your own risk!

I migrated SSP database to new SQL where SharePoint 2010 dbs resides and launched below script.


DECLARE
       @Old_RecodID bigint,
       @NT_Name NVARCHAR(400),
       @New_RecordID bigint
       
DECLARE UserLink_cursor CURSOR FOR

SELECT ssp.[RecordID] OldRecodID
      ,SSP.[NTName]
      , prof2020.[RecordID] NewRecordID
       FROM [SSP_DB_Intra2007].[dbo].[UserProfile_Full] SSP
     inner join   
       [UserProfiles-Profile-2010].[dbo].[UserProfile_Full] prof2020
       on 
       SSP.[NTName]=prof2020.[NTName]


OPEN UserLink_cursor;

-- Perform the first fetch.
FETCH NEXT FROM UserLink_cursor into @Old_RecodID, @NT_Name, @New_RecordID

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
   -- This is executed as long as the previous fetch succeeds.
   
   INSERT INTO [UserProfiles-Profile-2010].[dbo].[UserLinks]
           ([RecordId]
           ,[Title]
           ,[GroupType]
           ,[GroupTitle]
           ,[Url]
           ,[ContentClass]
           ,[PolicyId]
           ,[ItemSecurity]
           ,[PartitionID])
     SELECT 
       [RecordId] =@New_RecordID
      ,[Title]
      ,[GroupType]
      ,[GroupTitle]
      ,[Url]
      ,[ContentClass]
      ,[PolicyId]
      ,[ItemSecurity]
      
     -- check partition ID from your 2010 farm querying UserLinks table in db. It will be like the following 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx'.
      , '0C37852B-34D0-418E-91C6-2AC25AF4BE5B' 

  FROM [SSP_DB_Intra2007].[dbo].[UserLinks]
  where RecordId=@Old_RecodID
  
   
   FETCH NEXT FROM UserLink_cursor into @Old_RecodID, @NT_Name, @New_RecordID;
END

CLOSE UserLink_cursor;
DEALLOCATE UserLink_cursor;
GO


 --select * from [UserProfiles-Profile-2010].[dbo].[UserLinks]


Reference:
http://blogs.technet.com/b/meamcs/archive/2012/05/14/migrate-sharepoint-2007-my-links-to-sharepoint-2010.aspx