我用Montago的解決方案,但它轉換成做了工作的SQL代碼爲了我。可以自由地使用它,我希望它可以幫助你:)
USE DatabaseName
GO
DECLARE @sqlDrop VARCHAR(1000)
SET @sqlDrop = 'IF EXISTS (SELECT * FROM #table# WHERE object_id = OBJECT_ID(''#name#'')) DROP #what# #name#'
DECLARE @sqlCommand VARCHAR(1000)
DECLARE @id INT
SET @id = 0
DECLARE @name SYSNAME
DECLARE @prev INT
WHILE 1 = 1
BEGIN
/* find traces of synchronization */
-- to be sure that id changed
SET @prev = @id
-- get the next table
SELECT TOP 1
@id = object_id,
@name = name
FROM sys.tables
WHERE object_id > @id
ORDER BY object_id
-- confirm that there is next table
IF @id = @prev
BREAK
/* remove traces of synchronization */
-- remove table
SET @sqlCommand = @sqlDrop
SET @sqlCommand = REPLACE(@sqlCommand, '#table#', 'sys.tables')
SET @sqlCommand = REPLACE(@sqlCommand, '#name#', @name + '_tracking')
SET @sqlCommand = REPLACE(@sqlCommand, '#what#', 'TABLE')
EXEC (@sqlCommand)
-- remove triggers
SET @sqlCommand = @sqlDrop
SET @sqlCommand = REPLACE(@sqlCommand, '#table#', 'sys.triggers')
SET @sqlCommand = REPLACE(@sqlCommand, '#name#', @name + '_delete_trigger')
SET @sqlCommand = REPLACE(@sqlCommand, '#what#', 'TRIGGER')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_delete_trigger', '_insert_trigger')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_insert_trigger', '_update_trigger')
EXEC (@sqlCommand)
-- remove stored procedures
SET @sqlCommand = @sqlDrop
SET @sqlCommand = REPLACE(@sqlCommand, '#table#', 'sys.procedures')
SET @sqlCommand = REPLACE(@sqlCommand, '#name#', @name + '_delete')
SET @sqlCommand = REPLACE(@sqlCommand, '#what#', 'PROCEDURE')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_delete', '_deletemetadata')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_deletemetadata', '_insert')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_insert', '_insertmetadata')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_insertmetadata', '_selectchanges')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_selectchanges', '_selectrow')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_selectrow', '_update')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_update', '_updatemetadata')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_updatemetadata', '_bulkdelete')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_bulkdelete', '_bulkinsert')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, '_bulkinsert', '_bulkupdate')
EXEC (@sqlCommand)
END
-- remove scope and schema tables
SET @sqlCommand = @sqlDrop
SET @sqlCommand = REPLACE(@sqlCommand, '#table#', 'sys.tables')
SET @sqlCommand = REPLACE(@sqlCommand, '#name#', 'schema_info')
SET @sqlCommand = REPLACE(@sqlCommand, '#what#', 'TABLE')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, 'schema_info', 'scope_config')
EXEC (@sqlCommand)
SET @sqlCommand = REPLACE(@sqlCommand, 'scope_config', 'scope_info')
EXEC (@sqlCommand)
這一點,因爲你可以看到通過所有的表去,並試圖找到同步的痕跡。您只需更改數據庫名稱(第一行)。 另外,如果你想與你刪除的內容更安全,使用此代碼查找表:
-- get the next table
SELECT TOP 1
@id = object_id,
@name = REPLACE(name, '_tracking', '')
FROM sys.tables
WHERE object_id > @id
AND name LIKE '%_tracking'
ORDER BY object_id
這隻會尋找那些實際上正在同步
一個重要的優勢,只能重新調配,你改變的是,你把所有的元數據範圍和所有參與範圍 – Rabbi 2010-06-16 12:20:37