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