- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:dictionary:createindexsql

# createIndexSql

##### Syntax

    array createIndexSql(
        string $indexName,
        string $tableName,
        mixed $indexColumns,
        optional mixed $indexOptions=false
        )

## Description

The method `createIndexSql()` creates the SQL statement necessary to create an index, given by `$indexName` on an existing table, given by `$tableName`, with the attributes specified in the mixed variable `$indexColumns`. The index must not already exist on the specified table (unless the REPLACE `$indexOptions` attribute is provided). In some databases, the index name must be unique to the entire database.

In order to actually create the index, the returned array must be passed to the executeSqlArray() method.

## Parameters

### $indexName

An identifier for the index. The identifier must conform to any attributes designated by the DBMS, such as length and character set.

### $tableName

The parameter must indicate an existing table in the database.

### $indexColumns

The parameter contains the fields to be used in the index, in the order in which they are to appear. The parameter may be passed as either a string:

    $fields = 'COLUMN_1,COLUMN_2,COLUMN_3';

or as a numeric array:

    $fields = array('COLUMN_1','COLUMN_2','COLUMN_3');

In databases that support partial column indexing, the columns can be passed as `COLUMN_1(20)`.

### $indexOptions

An array of possible options to creating the index. Some options are database specific. To create a unique index, pass the array `('UNIQUE')`;

## Usage

    $dict = NewDataDictionary($db);
    $sqlarray = $dict->createIndexSql('SALESIDX','ACT', 'ACTMAXSALE,ACTNO');
    print_r($sqlarray);
    /*
    * prints
    *
    Array
    (
        [0] => CREATE INDEX SALESIDX ON ACT (ACTMAXSALE, ACTNO)
    )
    */

v5/dictionary/createindexsql.txt · Last modified: 2016/01/12 17:06 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top