CREATE  PROCEDURE scrubDatabase (
  @IncludeSiteRegistrations bit = 0
) AS
BEGIN TRAN
DECLARE @TableName nvarchar(25)
DECLARE @SQLStatement nvarchar(2000)
DECLARE sites CURSOR LOCAL FORWARD_ONLY READ_ONLY
  FOR SELECT CONVERT(nvarchar(25), [MachineName] + N'W3SVC' + 
  CONVERT(nvarchar(5), [SiteIndex])) AS [TableName] FROM [LogSite]

OPEN sites
FETCH NEXT FROM sites INTO @TableName
WHILE @@FETCH_STATUS = 0
  BEGIN
    IF EXISTS(SELECT * FROM dbo.sysobjects WHERE [ID] = 
      OBJECT_ID(@TableName) AND OBJECTPROPERTY([ID],
      N'IsUserTable') = 1)
      BEGIN
        IF (@IncludeSiteRegistrations = 1)
          BEGIN
            SET @SQLStatement = N'DROP TABLE ' + @TableName
            EXECUTE sp_executesql @SQLStatement
            SET @SQLStatement = N'DROP VIEW vw_' + @TableName
            EXECUTE sp_executesql @SQLStatement
          END
        ELSE
          BEGIN
            SET @SQLStatement = N'DELETE FROM ' + @TableName
            EXECUTE sp_executesql @SQLStatement
          END
      END
    FETCH NEXT FROM sites INTO @TableName
  END

DELETE FROM URIStem
DELETE FROM URIQuery
DELETE FROM Host
DELETE FROM Referer
DELETE FROM Cookie
DELETE FROM UserAgent
DELETE FROM LogSource
IF (@IncludeSiteRegistrations = 1)
  DELETE FROM LogSite

IF (@@ERROR <> 0)
  ROLLBACK TRAN
ELSE
  COMMIT TRAN
