header

Uninstallation script for YetAnotherForum schema in SQL
Posted on October 27, 2008 17:50 by menace

I installed YetAnotherForum on one of the site that I'm working on but ran into a few issues while doing an upgrade. I decided that I will start from a clean slate since this is a new installation, so I wasn't worry about data loss or anything of that nature. A lot of users has also demanded for such a function but the YAF hasn't released any yet to drop the tables and clean up the database scheme of any YAF installation. I compile and wrote a script tonight that will delete the YAF database schema so in any case that anybody would like to remove or start from the beginning with a clean DB.
Here's the script to do that:

Code (T-SQL):

   1: /* YAF DB SCHEMA UNINSTALL SQL SERVER SCRIPT
   2: Use at your own risk! */
   3: --Written by Dennis (menacestudio.com)
   4: --STEP #1
   5: --DROP ALL YAF STORED PROCEDURES
   6: USE [tablename]
   7: GO
   8: declare @procName sysname
   9: declare someCursor cursor FOR
  10: SELECT name FROM sysobjects WHERE type = 'P' AND objectproperty(id, 'IsMSShipped') = 0 and name like 'yaf%'
  11: open someCursor
  12: fetch next FROM someCursor INTO @procName
  13: while @@FETCH_STATUS = 0
  14: begin
  15: exec('drop proc ' + @procName)
  16: fetch next FROM someCursor INTO @procName
  17: end
  18: close someCursor
  19: deallocate someCursor
  20: go
  21: --STEP #2
  22: --DROP ALL YAF CONSTRAINTS
  23: DECLARE @table nvarchar(50)
  24: declare @schema nvarchar(128), @tbl nvarchar(128), @constraint nvarchar(128)
  25: DECLARE @sql nvarchar(255)
  26: declare cur cursor fast_forward for
  27: select distinct cu.constraint_schema, cu.table_name, cu.constraint_name
  28: from information_schema.table_constraints tc
  29: join information_schema.referential_constraints rc on rc.unique_constraint_name = tc.constraint_name
  30: join information_schema.constraint_column_usage cu on cu.constraint_name = rc.constraint_name
  31: where tc.table_name like 'yaf%'
  32: open cur
  33: fetch next from cur into @schema, @tbl, @constraint
  34: while @@fetch_status <> -1
  35: begin
  36: select @sql = 'ALTER TABLE ' + @tbl + ' DROP CONSTRAINT ' + @constraint
  37: exec sp_executesql @sql
  38: fetch next from cur into @schema, @tbl, @constraint
  39: end
  40: close cur
  41: deallocate cur
  42: --STEP #3
  43: --DROP ALL YAF TABLES
  44: USE [tablename]
  45: GO
  46: declare @tableName sysname
  47: declare someCursor cursor FOR
  48: --search through stored procedures
  49: SELECT name FROM sysobjects WHERE name like 'yaf%' and type = 'U'
  50: open someCursor
  51: fetch next FROM someCursor INTO @tableName
  52: while @@FETCH_STATUS = 0
  53: begin
  54: exec('drop table ' + @tableName)
  55: fetch next FROM someCursor INTO @tableName
  56: end
  57: close someCursor
  58: deallocate someCursor
  59: go

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



     

Blog Menu

Recent Posts Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
Current date is: Wednesday, January 07, 2009
Copyright © Menace Studio 2005-2009. Dennis Rongo. All rights reserved.