@Override
 protected Query createQuery(
     InspectionContext inspectionContext, TableInspectionScope tableInspectionScope) {
   Collection<String> filters = newArrayList();
   Collection<Object> parameters = newArrayList();
   if (tableInspectionScope.getSchema() != null) {
     filters.add("S.SEQUENCE_SCHEMA=?");
     parameters.add(tableInspectionScope.getSchema());
   }
   if (tableInspectionScope.getTable() != null) {
     filters.add("C.TABLE_NAME=?");
     parameters.add(tableInspectionScope.getTable());
   }
   return new ParameterizedQuery(newQuery(where(QUERY, filters, AND)), parameters);
 }
  @Override
  protected Query createQuery(
      InspectionContext inspectionContext, TableInspectionScope tableInspectionScope) {
    Collection<Object> parameters = newArrayList();
    SelectQuery selectColumn = new SelectQuery();
    if (isEmpty(tableInspectionScope.getCatalog())) {
      selectColumn.column("db_name() as table_catalog");
    } else {
      selectColumn.column("? as table_catalog");
      parameters.add(tableInspectionScope.getCatalog());
    }
    selectColumn.column("schemas.name as table_schema");
    selectColumn.column("tables.name as table_name");
    selectColumn.column("columns.name as column_name");

    String catalog =
        isEmpty(tableInspectionScope.getCatalog()) ? "" : (tableInspectionScope.getCatalog() + ".");
    selectColumn.from(catalog + "sys.schemas");
    selectColumn.innerJoin(catalog + "sys.tables", "schemas.schema_id=tables.schema_id");
    selectColumn.innerJoin(catalog + "sys.columns", "columns.object_id=tables.object_id");

    if (!isEmpty(tableInspectionScope.getSchema())) {
      selectColumn.where("schemas.name=?");
      parameters.add(tableInspectionScope.getSchema());
    }
    if (!isEmpty(tableInspectionScope.getTable())) {
      selectColumn.where("tables.name=?");
      parameters.add(tableInspectionScope.getTable());
    }
    selectColumn.where("is_identity=1");

    SelectQuery selectTable = new SelectQuery();
    selectTable.column("c.*");
    selectTable.column(
        "quotename(table_catalog) + '.' + quotename(table_schema) + '.' + quotename(table_name) as table_qualified_name");
    selectTable.from("(" + selectColumn + ") c");

    SelectQuery selectIdentity = new SelectQuery();
    selectIdentity.column("c.*");
    selectIdentity.column("ident_seed(table_qualified_name) as start_with");
    selectIdentity.column("ident_current(table_qualified_name) as last_value");
    selectIdentity.column("ident_incr(table_qualified_name) as increment_by");
    selectIdentity.from("(" + selectTable + ") c");
    return new ParameterizedQuery(selectIdentity, parameters);
  }