Thursday 19 August 2010

SyncEntry_ and SubscriptionStatistics_ tables

If you have a look at your database, you may notice several SyncEntry_ and SubscriptionStatistics_ tables.

Ever wondered what they are? These tables are for use with Outlook clients. You will have 2 of each table for each online client, and 3 of each table for each offline client. Additionally these tables are per user, per machine... so if a user changes computer then there will be more tables for that user.

On a related note, you can actually remove these tables in a supported fashion if you arent using them - the UK CRM team posted a topic on ow to do this here:

http://blogs.msdn.com/ukdynsupport/archive/2009/05/07/script-to-clean-up-syncentry-guid-and-subscriptionstatistics-guid-tables-in-the-sql-database.aspx

The code is reproduced below for your convenience...

Declare  @SyncEnt  char(60),
   @sql   nchar(100),
   @sqlSync        nchar(100),
   @DN             char(50)
                
Declare User_cursor CURSOR for
                
select DomainName from SystemUserBase
                
 OPEN User_cursor
 FETCH NEXT FROM User_cursor INTO @DN
                
WHILE @@Fetch_Status = 0
BEGIN
 DECLARE CRMSync_cursor CURSOR FOR
 select substring(SyncEntryTableName,11,42) as SyncEntryGUID from subscription where systemuserid in
    (select systemuserid from systemuserbase where domainname =@DN) 

 OPEN CRMSync_cursor 

 FETCH NEXT FROM CRMSync_cursor INTO @SyncEnt 

 WHILE @@Fetch_Status = 0
 BEGIN
  SELECT @sql = 'DROP TABLE SubscriptionStatistics_' +(@SyncEnt)
  SELECT @sqlSync = 'DROP TABLE SyncEntry_' +(@SyncEnt) 

  EXEC sp_executesql @sql
  EXEC sp_executesql @sqlSync
  FETCH NEXT FROM CRMSync_cursor INTO @SyncEnt
 END 

 CLOSE CRMSync_cursor
 DEALLOCATE CRMSync_cursor

 delete from subscriptionclients where subscriptionid in
    (select subscriptionid from subscription where systemuserid in 
    (select systemuserid from systemuserbase where domainname = @DN)) 

 delete from Subscriptionsyncinfo where subscriptionid in
 (select subscriptionid from subscription where systemuserid in
    (select systemuserid from systemuserbase  where domainname = @DN)) 

 -- Please Uncomment The 3 lines below if you are on UR7 or Higher
 -- delete from SubscriptionManuallyTrackedObject where subscriptionid in
 -- (select subscriptionid from subscription where systemuserid in
 -- (select systemuserid from systemuserbase where domainname = @DN)) 

 delete from subscription where systemuserid in
    (select systemuserid from systemuserbase where domainname = @DN) 

     FETCH NEXT FROM User_cursor INTO @DN
END 

CLOSE User_cursor
DEALLOCATE User_cursor

No comments:

Post a Comment