RemoveUnreferencedRows Utility

Command-line Help

The RemoveUnreferencedRows utility supports both the -? command and the -Help command to access its command-line help.

The following code sample shows the contents of the command-line help:
Common resource tables (child tables) like Comments and ESignatures are 
referenced by many tables (parent tables). When the parent tables are filtered, 
rows in the child tables may be left with no remaining references and should be removed. 
The utility generates a script to remove rows that have become unreferenced.
  
Arguments may be prefixed by '/' or '-'
  
Usage: RemoveUnreferencedRows.exe -ReferencedTablesFile <String> -Server <String> 
-TargetDatabase <String> [-Help] [-Password <String>] [-UserName <String>]
    -ReferencedTablesFile <String>
        File containing the XML definition of the referenced (child) tables
        Alias: -f.
    -Server <String>
        Address of the database server Alias: -d.
    -TargetDatabase <String>
        Name of the target database Alias: -t.
    -Help [<Boolean>]
        Displays this help message. Alias: -?.
    -Password <String>
        SQL User Password (SQL Server Authentication) Alias: -p.
    -UserName <String>
        SQL User Name (SQL Server Authentication) Alias: -u.

Referenced Tables File

The RemoveUnreferencedRows utility uses the ReferencedTables.xml file that defines a set of referenced child tables to find orphans. The XML code is a serialization of a collection of ReferencedTable instances. You can download this file from https://github.build.ge.com/BM/FilteredDatabaseCopy.

The following code sample shows the contents of the ReferencedTable.cs file:
/// <summary>
    /// Defines a child table that is referenced from multiple tables by
    /// reference ID. The rows of a child table should be removed when all
    /// referencing rows are removed.
    /// </summary>
    [Serializable]
    public class ReferencedTable
    {
        /// <summary>
        /// Referenced (child) table name.
        /// </summary>
        public string TableName { get; set; }
  
        /// <summary>
        /// Referenced table's key column name.
        /// </summary>
        public string KeyColumn { get; set; }
  
        /// <summary>
        /// Referenced tables' key column type (e.g. "int")
        /// </summary>
        public string KeyType { get; set; }
  
        /// <summary>
        /// Optional column name in the referenced table to support chaining
        /// of rows wthin the referenced table. The chaining column should contain
        /// a reference to the ReferencedTable for the row representing the top
        /// of the chain which would be referenced by parent rows.
        /// </summary>
        public string ChainingColumn { get; set; }
  
        /// <summary>
        /// The REGEX pattern for the column name in the parent tables that
        /// contains references to the ReferencedTable. Pattern is not case sensitive.
        /// E.g. .*comment[_]?id finds all columns ending with comment_id or
        /// commentid
        /// </summary>
        public string ReferringColumnPattern { get; set; }
}
Note:
In the ReferencedTables.xml file, define the referenced table files in an order. If a referenced table references another table (for example, ESignature references Comments), the referencing table should appear first so that its orphans are removed first (for example, ESignature should appear before Comments). This may orphan more rows in its referenced table