class MsSqlServerDatabaseMeta extends BaseDatabaseMeta implements IDatabase {

    @Override
    public boolean checkIndexExists(Database database, String schemaName, String tableName, String[] idxFields) throws HopDatabaseException {

        String tablename = database.getDatabaseMeta().getQuotedSchemaTableCombination(schemaName, tableName);

        boolean[] exists = new boolean[idxFields.length];
        for (int i = 0; i < exists.length; i++) {
            exists[i] = false;
        }

        try {
            //
            // Get the info from the data dictionary...
            //
            StringBuilder sql = new StringBuilder(128);
            sql.append("select i.name table_name, c.name column_name ");
            sql.append("from     sysindexes i, sysindexkeys k, syscolumns c ");
            sql.append("where    i.name = '" + tablename + "' ");
            sql.append("AND      i.id = k.id ");
            sql.append("AND      i.id = c.id ");
            sql.append("AND      k.colid = c.colid ");

            ResultSet res = null;
            try {
                res = database.openQuery(sql.toString());
                if (res != null) {
                    Object[] row = database.getRow(res);
                    while (row != null) {
                        String column = database.getReturnRowMeta().getString(row, "column_name", "");
                        int idx = Const.indexOfString(column, idxFields);
                        if (idx >= 0) {
                            exists[idx] = true;
                        }

                        row = database.getRow(res);
                    }
                } else {
                    return false;
                }
            } finally {
                if (res != null) {
                    database.closeQuery(res);
                }
            }

            // See if all the fields are indexed...
            boolean all = true;
            for (int i = 0; i < exists.length && all; i++) {
                if (!exists[i]) {
                    all = false;
                }
            }

            return all;
        } catch (Exception e) {
            throw new HopDatabaseException("Unable to determine if indexes exists on table [" + tablename + "]", e);
        }
    }

}