· Chris Hammond
Last Updated

Deleting unused blogs and photo galleries in CommunityServer.

Learn how to clean up unused blogs and photo galleries on CommunityServer sites with this ROUGH SQL code. Use with caution and always back up your database first! #SQLMaintenance #CommunityServer Posted on weblogs.asp.net/christoc

Learn how to clean up unused blogs and photo galleries on CommunityServer sites with this ROUGH SQL code. Use with caution and always back up your database first! #SQLMaintenance #CommunityServer Posted on weblogs.asp.net/christoc

I decided to remove some unused blogs and photo galleries from a few of my CommunityServer sites today. Here’s some ROUGH SQL code to do it.

It worked for me, but I make no guarantees how it will work for you! Backup your database before performing any type of maintenance.

Be sure to substitute your UserId where I note below with ##. I run the commented-out code first at the top to create a quick table. After doing my testing, I commit the changes and drop the table I created.

I don’t claim this code is great, but it got the job done. 😄

/*
create table temp_deletesections
(
    SectionId int,
    Processed int default 0
)
*/

begin tran
--rollback

declare @rowsAdded int

insert into temp_deletesections
select sectionid, 0 
from cs_sections
where totalposts < 1

set @rowsAdded = @@rowcount

while @rowsAdded > 0
begin
    declare @sectionDeleteId int

    select top 1 @sectionDeleteId = sectionId 
    from temp_deletesections 
    where Processed = 0

    exec dbo.cs_Section_CreateUpdateDelete 
        @SectionID = @sectionDeleteId, 
        @DeleteForum = 1, 
        @SettingsID = 1000, 
        @UserID = ##

    update temp_deletesections 
    set Processed = 1 
    where Processed = 0 
    and sectionId = @sectionDeleteId

    set @rowsAdded = @rowsAdded - 1
end

--commit
--drop table temp_deletesections

Note: Always review and test SQL code in a safe environment before applying it to production databases.
Back to Blog

Related Posts

View All Posts »
Welcome to CommunityServer2007

Welcome to CommunityServer2007

Discover the latest upgrade at weblogs.asp.net with insightful tips for reworking your skin for CommunityServer 2007. Stay updated!