iFinity Blogs 

Clean out the tables from a DotNetNuke Database

Sep 8

Written by:
Wednesday, September 08, 2010 2:37 PM  RssIcon

Every now and again I get a failed DNN installation with a half-created database.  When that happens, the best course of action is to clean out the database and start again with the install, making sure the problem is fixed.  But how do you clean out the database?

Here’s a quick script I wrote to do this – to be run through a Sql query tool.

Note : don’t ever run this unless you want to actually destroy your DotNetNuke database.  It’s a scorched earth deletion. It’s the Sql equivalent of delete *.* in old DOS days – except Sql Server won’t give you an ‘Are you sure?’ prompt.

Here’s the script:

declare @tableName nvarchar(100), @sql nvarchar(255)
declare drop_curs cursor for
select Name from sysobjects
where type = 'u'
and (name like 'dnn_%' or name like ‘aspnet_%’)

open drop_curs
fetch from drop_curs into @tablename
while @@fetch_status = 0
begin
    select @sql = 'drop table ' + @tablename
    execute (@sql)

fetch from drop_curs into @tablename
end
close drop_curs
deallocate drop_curs

Tags:
Categories:
Location: Blogs Parent Separator Crafty Code

2 comment(s) so far...


Gravatar

Re: Clean out the tables from a DotNetNuke Database

Great script!

But why "... name like 'dnn_%' ...". Do not think all uses "dnn" as qualifier.

You should add qualifier as param to this query, because at the one DB can be more then one DNN installations ;)

By Sergey on   Thursday, September 09, 2010 3:09 AM
Gravatar

Re: Clean out the tables from a DotNetNuke Database

@sergey : yes, you're right. If you don't use the dnn_ prefix, you'll have to figure out another way.

I *always* suggest using the prefix. It's good database management to use table prefixes to define systems and subsystems.

By Bruce Chapman on   Thursday, September 09, 2010 10:07 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
Bruce Chapman
Hi, I'm Bruce Chapman, and this is my blog. You'll find lots of information here - my thoughts about business and the internet, technical information, things I'm working on and the odd strange post or two.

 

Share this
Get more!
Subscribe to the Mailing List
Email Address:
First Name:
Last Name:
You will be sent a confirmation upon subscription

 

Follow me on Twitter
Stack Exchange
profile for Bruce Chapman at Stack Overflow, Q&A for professional and enthusiast programmers
Klout Profile