O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
O Guia Definitivo do Yii 1.1
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
the new column name. The query builder will quote the table name as well as the column<br />
names properly.<br />
Below is an example showing how to rename a table column:<br />
// ALTER TABLE `tbl_users` CHANGE `name` `username` varchar(255) NOT NULL<br />
renameColumn('tbl_user', 'name', 'username')<br />
alterColumn<br />
function alterColumn($table, $column, $type)<br />
The alterColumn method builds and executes a SQL statement for altering a table column.<br />
The $table parameter specifies the name of the table whose column is to be altered. The<br />
$column parameter specifies the name of the column to be altered. And $type specifies<br />
the new definition of the column. Column definition can contain abstract data type, as<br />
described in the subsection of "createTable". The query builder will quote the table name<br />
as well as the column name properly.<br />
Below is an example showing how to alter a table column:<br />
// ALTER TABLE `tbl_user` CHANGE `username` `username` varchar(255) NOT NULL<br />
alterColumn('tbl_user', 'username', 'string NOT NULL')<br />
addForeignKey<br />
function addForeignKey($name, $table, $columns,<br />
$refTable, $refColumns, $delete=null, $update=null)<br />
The addForeignKey method builds and executes a SQL statement for adding a foreign key<br />
constraint to a table. The $name parameter specifies the name of the foreign key. The<br />
$table and $columns parameters specify the table name and column name that the foreign<br />
key is about. If there are multiple columns, they should be separated by comma<br />
characters. The $refTable and $refColumns parameters specify the table name and<br />
column name that the foreign key references. The $delete and $update parameters<br />
specify the ON DELETE and ON UPDATE options in the SQL statement, respectively.<br />
Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT,<br />
SET NULL. The query builder will properly quote the table name, index name and column<br />
name(s).<br />
Below is an example showing how to add a foreign key constraint,