private long CopyTableMissingKeys(Table sourceTable, ForeignKey sourceForeignKey, Database targetDatabase, CopyPortion portion)
        {
            long   ret;
            String sql;
            Table  targetTable = targetDatabase.Tables[sourceForeignKey.ReferencedTable, sourceForeignKey.ReferencedTableSchema];

            if (sourceTable.RowCount > 0)
            {
                sql = GetSqlCopyDataMissingKeys(sourceForeignKey);
            }
            else
            {
                uint percent = portion.AsPercentage();
                sql = GetSqlSampleCopy(sourceTable, percent);
            }
            using (SqlConnection sourceConnection = sourceServer.ConnectionContext.SqlConnectionObject)
            {
                sourceConnection.Open();
                sourceConnection.ChangeDatabase(targetDatabase.Name);
                using (SqlCommand sqlMissingKeysCommand = new SqlCommand(sql, sourceConnection))
                {
                    ret = this.BulkCopyData(sourceTable, sqlMissingKeysCommand, targetTable);
                }
                sourceConnection.Close();
                return(ret);
            }
        }
        private long CopyTableTopN(Table sourceTable, Table targetTable, CopyPortion portion)
        {
            uint percent = portion.AsPercentage();
            long ret     = 0;

            String sql = GetSqlTopNCopy(sourceTable, percent);

            using (SqlConnection sourceConnection = sourceServer.ConnectionContext.SqlConnectionObject)
            {
                sourceConnection.Open();
                sourceConnection.ChangeDatabase(sourceTable.Parent.Name);
                using (SqlCommand sqlCommand = new SqlCommand(sql, sourceConnection))
                {
                    ret = this.BulkCopyData(sourceTable, sqlCommand, targetTable);
                }
                sourceConnection.Close();
            }
            return(ret);
        }