1 DECLARE @base nvarchar(max),
5 SET @base = 'ALTER TABLE /*_*/recentchanges DROP CONSTRAINT ';--
8 FROM sys.foreign_keys fk
9 JOIN sys.foreign_key_columns fkc
10 ON fkc.constraint_object_id = fk.object_id
12 ON c.column_id = fkc.parent_column_id
13 AND c.object_id = fkc.parent_object_id
15 fk.parent_object_id = OBJECT_ID('/*_*/recentchanges')
16 AND fk.referenced_object_id = OBJECT_ID('/*_*/page')
17 AND c.name = 'rc_cur_id';--
19 SET @SQL = @base + @id;--
21 EXEC sp_executesql @SQL;--
24 FROM sys.foreign_keys fk
25 JOIN sys.foreign_key_columns fkc
26 ON fkc.constraint_object_id = fk.object_id
28 ON c.column_id = fkc.parent_column_id
29 AND c.object_id = fkc.parent_object_id
31 fk.parent_object_id = OBJECT_ID('/*_*/recentchanges')
32 AND fk.referenced_object_id = OBJECT_ID('/*_*/revision')
33 AND c.name = 'rc_this_oldid';--
35 SET @SQL = @base + @id;--
37 EXEC sp_executesql @SQL;--
40 FROM sys.foreign_keys fk
41 JOIN sys.foreign_key_columns fkc
42 ON fkc.constraint_object_id = fk.object_id
44 ON c.column_id = fkc.parent_column_id
45 AND c.object_id = fkc.parent_object_id
47 fk.parent_object_id = OBJECT_ID('/*_*/recentchanges')
48 AND fk.referenced_object_id = OBJECT_ID('/*_*/revision')
49 AND c.name = 'rc_last_oldid';--
51 SET @SQL = @base + @id;--
53 EXEC sp_executesql @SQL;--
55 -- while we're at it, let's fix up the other foreign key constraints on recentchanges
56 -- as future patches touch constraints on other tables, they'll take the time to update constraint names there as well
57 ALTER TABLE /*_*/recentchanges DROP CONSTRAINT FK_rc_logid_log_id;--
58 ALTER TABLE /*_*/recentchanges ADD CONSTRAINT rc_logid__log_id__fk FOREIGN KEY (rc_logid) REFERENCES /*_*/logging(log_id) ON DELETE CASCADE;--
61 FROM sys.foreign_keys fk
62 JOIN sys.foreign_key_columns fkc
63 ON fkc.constraint_object_id = fk.object_id
65 ON c.column_id = fkc.parent_column_id
66 AND c.object_id = fkc.parent_object_id
68 fk.parent_object_id = OBJECT_ID('/*_*/recentchanges')
69 AND fk.referenced_object_id = OBJECT_ID('/*_*/mwuser')
70 AND c.name = 'rc_user';--
72 SET @SQL = @base + @id;--
74 EXEC sp_executesql @SQL;--
76 ALTER TABLE /*_*/recentchanges ADD CONSTRAINT rc_user__user_id__fk FOREIGN KEY (rc_user) REFERENCES /*_*/mwuser(user_id);