# Working with Indexes

## getTableIndexes(*$table*)

Get an array of indexes defined on *$table*

Each array entry is in the form:

```php
    'indexname' => array(
        'columns' => 'column1, column2',
        'unique' => false
    )
```

Returns an array of indexes on success, or *false* on error. Additional information may be available using getLastError() and getLastErrNo().

## addPrimaryKey(*$table*, *$column*)

Queue instruction needed to add new primary key definition (*$column*) for *$table* to the work queue. The *$column* string may be a single column name or a comma separated list of column names. A [primary key](https://en.wikipedia.org/wiki/Unique_key#Defining_primary_keys_in_SQL) must be unique.

Returns *true* on success, or *false* on error. Additional information may be available using getLastError() and getLastErrNo().

## addIndex(*$name*, *$table*, *$column*, *$unique*)

Queue instruction needed to create a new index named *$name* to *$table* with definition *$column* to the work queue. The *$column* string may be a single column name or a comma separated list of column names. If *$unique* is specified as *true*, the index will be specified as unique.

Returns *true* on success, or *false* on error. Additional information may be available using getLastError() and getLastErrNo().

## dropIndex(*$name*, *$table*)

Queue instruction needed to drop the index named *$name* on *$table* to the work queue.

Returns *true* on success, or *false* on error. Additional information may be available using getLastError() and getLastErrNo().

## dropIndexes(*$table*)

Add drop index for all (non-PRIMARY) keys for a *$table* to the work queue. This can be used to clean up indexes with automatically generated names.

Returns *true* on success, or *false* on error. Additional information may be available using getLastError() and getLastErrNo().

## dropPrimaryKey(*$table*)

Queue instruction needed to drop the primary key definition on *$table* to the work queue.

Returns *true* on success, or *false* on error. Additional information may be available using getLastError() and getLastErrNo().


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xoops.gitbook.io/xmf-cookbook/reference/database/tables/working-with-indexes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
