Deleting unused blogs and photo galleries in CommunityServer.

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 sub in your UserId where I note below with the ##. I run the commented out code first at the top, this creates a quick table, after doing my testing I commit the changes then drop the table I had created.

I don't claim this code is great, but it got the job done :D

/*

create table temp_deletesections

(

SectionId int,

Processed int default 0

)

*/

begin tran

tran

--rollback

declare @rowsAdded int

insert into temp_deletesections

@rowsAdded int

insert into temp_deletesections

into temp_deletesections

select sectionid, 0 from cs_sections

sectionid, 0 from cs_sections

where totalposts <1

totalposts <1

set @rowsAdded = @@rowcount

@rowsAdded = @@rowcount

while @rowsAdded > 0

begin

declare @sectionDeleteId int

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

@rowsAdded > 0

begin

declare @sectionDeleteId int

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

begin

declare @sectionDeleteId int

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

@sectionDeleteId int

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

top 1 @sectionDeleteId = sectionId from temp_deletesections where processed=0

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

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

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

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

set @rowsAdded = @rowsAdded-1

@rowsAdded = @rowsAdded-1

end

--commit

--drop table temp_deletesections

 

Posted from weblogs.asp.net/christoc

Recent Comments

There are currently no comments. Be the first to make a comment.

Add Comment

Please add your comment by filling out the field(s) below. Your comment may need to be approved before it becomes visible.
Enter your first name for display with the comment
Enter your last name for display with the comment.
Enter your comment here.
If you can't type DNNRocks in, you can't post, plain and simple.
Submit Comment Cancel

Chris Hammond

Chris Hammond is a father, husband, leader, software developer, photographer and car guy. Chris focuses on the latest in technology including artificial intelligence (AI) and has spent decades becoming an expert in ASP.NET and DotNetNuke (DNN) development. You will find a variety of posts relating to those topics here on the website. For more information check out the about Chris Hammond page.

Find me on Twitter, GitHub and LinkedIn.