20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ALTER TABLE `tbl_profile` ADD CONSTRAINT `fk_profile_user_id`<br />

// FOREIGN KEY (`user_id`) REFERENCES `tbl_user` (`id`)<br />

// ON DELETE CASCADE ON UPDATE CASCADE<br />

addForeignKey('fk_profile_user_id', 'tbl_profile', 'user_id',<br />

'tbl_user', 'id', 'CASCADE', 'CASCADE')<br />

dropForeignKey<br />

function dropForeignKey($name, $table)<br />

The dropForeignKey method builds and executes a SQL statement for dropping a foreign<br />

key constraint. The $name parameter specifies the name of the foreign key constraint to<br />

be dropped. The $table parameter specifies the name of the table that the foreign key is<br />

on. The query builder will quote the table name as well as the constraint names properly.<br />

Below is an example showing how to drop a foreign key constraint:<br />

// ALTER TABLE `tbl_profile` DROP FOREIGN KEY `fk_profile_user_id`<br />

dropForeignKey('fk_profile_user_id', 'tbl_profile')<br />

createIndex<br />

function createIndex($name, $table, $column, $unique=false)<br />

The createIndex method builds and executes a SQL statement for creating an index. The<br />

$name parameter specifies the name of the index to be created. The $table parameter<br />

specifies the name of the table that the index is on. The $column parameter specifies the<br />

name of the column to be indexed. And the $unique parameter specifies whether a unique<br />

index should be created. If the index consists of multiple columns, they must be separated<br />

by commas. The query builder will properly quote the table name, index name and column<br />

name(s).<br />

Below is an example showing how to create an index:<br />

// CREATE INDEX `idx_username` ON `tbl_user` (`username`)<br />

createIndex('idx_username', 'tbl_user')<br />

dropIndex<br />

function dropIndex($name, $table)<br />

The dropIndex method builds and executes a SQL statement for dropping an index. The<br />

$name parameter specifies the name of the index to be dropped. The $table parameter<br />

specifies the name of the table that the index is on. The query builder will quote the table<br />

name as well as the index names properly.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!