====== createIndexSql ======
~~NOTOC~~
== 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 [[v5:dictionary:executesqlarray|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)
)
*/