Yii学习(十)数据库 Query Builder 下
2012-09-19 14:53
337 查看
数据表操作
createTable(): creates a table
renameTable(): renames a table
dropTable(): drops a table
truncateTable(): truncates a table
addColumn(): adds a table column
renameColumn(): renames a table column
alterColumn(): alters a table column
dropColumn(): drops a table column
createIndex(): creates an index
dropIndex(): drops an index
属性
pk: a generic primary key type, will be converted into int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY for MySQL;
string: string type, will be converted into varchar(255) for MySQL;
text: text type (long string), will be converted into text for MySQL;
integer: integer type, will be converted into int(11) for MySQL;
float: floating number type, will be converted into float for MySQL;
decimal: decimal number type, will be converted into decimal for MySQL;
datetime: datetime type, will be converted into datetime for MySQL;
timestamp: timestamp type, will be converted into timestamp for MySQL;
time: time type, will be converted into time for MySQL;
date: date type, will be converted into date for MySQL;
binary: binary data type, will be converted into blob for MySQL;
boolean: boolean type, will be converted into tinyint(1) for MySQL;
money: money/currency type, will be converted into decimal(19,4) for MySQL. This type has been available since version 1.1.8.
Just beginning!
createTable():
renameTable():
dropTable():
truncateTable():
addColumn():
dropColumn():
renameColumn():
alterColumn():
addForeignKey():
dropForeignKey():
createIndex():
dropIndex():
createTable(): creates a table
renameTable(): renames a table
dropTable(): drops a table
truncateTable(): truncates a table
addColumn(): adds a table column
renameColumn(): renames a table column
alterColumn(): alters a table column
dropColumn(): drops a table column
createIndex(): creates an index
dropIndex(): drops an index
属性
pk: a generic primary key type, will be converted into int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY for MySQL;
string: string type, will be converted into varchar(255) for MySQL;
text: text type (long string), will be converted into text for MySQL;
integer: integer type, will be converted into int(11) for MySQL;
float: floating number type, will be converted into float for MySQL;
decimal: decimal number type, will be converted into decimal for MySQL;
datetime: datetime type, will be converted into datetime for MySQL;
timestamp: timestamp type, will be converted into timestamp for MySQL;
time: time type, will be converted into time for MySQL;
date: date type, will be converted into date for MySQL;
binary: binary data type, will be converted into blob for MySQL;
boolean: boolean type, will be converted into tinyint(1) for MySQL;
money: money/currency type, will be converted into decimal(19,4) for MySQL. This type has been available since version 1.1.8.
Just beginning!
createTable():
function createTable($table, $columns, $options=null) // CREATE TABLE `tbl_user` ( // `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, // `username` varchar(255) NOT NULL, // `location` point // ) ENGINE=InnoDB createTable('tbl_user', array( 'id' => 'pk', 'username' => 'string NOT NULL', 'location' => 'point', ), 'ENGINE=InnoDB')
renameTable():
function renameTable($table, $newName) // RENAME TABLE `tbl_users` TO `tbl_user` renameTable('tbl_users', 'tbl_user')
dropTable():
function dropTable($table) // DROP TABLE `tbl_user` dropTable('tbl_user')
truncateTable():
function truncateTable($table) // TRUNCATE TABLE `tbl_user` truncateTable('tbl_user')
addColumn():
function addColumn($table, $column, $type) // ALTER TABLE `tbl_user` ADD `email` varchar(255) NOT NULL addColumn('tbl_user', 'email', 'string NOT NULL')
dropColumn():
function dropColumn($table, $column) // ALTER TABLE `tbl_user` DROP COLUMN `location` dropColumn('tbl_user', 'location')
renameColumn():
function renameColumn($table, $name, $newName) // ALTER TABLE `tbl_users` CHANGE `name` `username` varchar(255) NOT NULL renameColumn('tbl_user', 'name', 'username')
alterColumn():
function alterColumn($table, $column, $type) // ALTER TABLE `tbl_user` CHANGE `username` `username` varchar(255) NOT NULL alterColumn('tbl_user', 'username', 'string NOT NULL')
addForeignKey():
// ALTER TABLE `tbl_profile` ADD CONSTRAINT `fk_profile_user_id` // FOREIGN KEY (`user_id`) REFERENCES `tbl_user` (`id`) // ON DELETE CASCADE ON UPDATE CASCADE addForeignKey('fk_profile_user_id', 'tbl_profile', 'user_id', 'tbl_user', 'id', 'CASCADE', 'CASCADE')
dropForeignKey():
function dropForeignKey($name, $table) // ALTER TABLE `tbl_profile` DROP FOREIGN KEY `fk_profile_user_id` dropForeignKey('fk_profile_user_id', 'tbl_profile')
createIndex():
function createIndex($name, $table, $column, $unique=false) // CREATE INDEX `idx_username` ON `tbl_user` (`username`) createIndex('idx_username', 'tbl_user')
dropIndex():
function dropIndex($name, $table) // DROP INDEX `idx_username` ON `tbl_user` dropIndex('idx_username', 'tbl_user')
相关文章推荐
- YII Framework学习教程-YII的Model-数据库操作4-Query Builder使用举例
- Yii学习(九)数据库 Query Builder 上
- YII Framework学习教程-YII的Model-数据库操作1-CActiveRecord
- yii 学习笔记七、数据库连接配置
- <yii 框架学习> <转> 关于yii数据库添加新字段之后model类的修改
- YII Framework学习教程-YII的Model-数据库操作3-自定义的DAO操作
- yii框架学习经历-6.4数据库迁移
- 关于我学习Yii框架 - 数据库relation的使用
- Yii学习笔记-数据库访问
- YII Framework学习教程-YII的Model-数据库操作2-Relational Active Record翻译补全
- Yii框架官方指南系列24——使用数据库:Query Builder
- 关于后盾网yii框架的学习小结(6)--数据库连接配置与模型定义与后台登陆验
- YII Framework学习教程-YII的Model-数据库操作2-多关系的CActiveRecord使用举例
- Laravel学习笔记(五)---操作数据库--查询构建器(Query Builder)
- YII Framework学习教程-YII的Model-数据库操作1-CActiveRecord
- Yii的学习(3)--查询生成器 (Query Builder)
- yii 学习笔记值 如何批量像数据库插入数据
- 关于后盾网yii框架的学习小结(6)--数据库连接配置与模型定义与后台登陆验
- YII Framework学习教程-YII的Model-数据库操作4-<Query Builder>翻译
- YII Framework学习教程-YII的Model-数据库操作3-自定义的DAO操作