`
zfj.rails
  • 浏览: 46642 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Table.update_all也可以用:conditions

阅读更多

文档:

update_all(updates, conditions = nil, options = {}) 




例子:

Billing.update_all( "author = 'David'", "title LIKE '%Rails%'" )
/*
mysql > update billings set author = 'David' where title LIKE '%Rails%';
*/


也可以这样写:
author = 'David'
title = 'Rails'
Billing.update_all(["author = ?", author], ["title like ?", "%#{title}%"])


也是可以传变量的喔。这样写安全些。
分享到:
评论

相关推荐

    笔记.docx

    - 使用 `UPDATE table_name SET column_name = value WHERE condition;` 更新表中的数据。 - 示例:更新 `students` 表中 `id` 为 1 的学生的 `name` 为 "Tom",命令为 `UPDATE students SET name = 'Tom' WHERE ...

    Software Testing and Continuous Quality Improvement

    Software Testing and Continuous Quality Improvement <br>SECTION I SOFTWARE QUALITY IN PERSPECTIVE . . . . . . . . . . . . . . . 1 1 Quality Assurance Framework. . . . . . . ........

    mysqlSQL语法.pdf

    - `IN` 用于判断某个值是否在子查询结果集中,如 `WHERE column1 IN (SELECT column1 FROM table2 WHERE conditions)`。 7. **模糊查询**: - `LIKE` 用于进行模式匹配,如 `WHERE column1 LIKE 'x%'` 查找以 'x'...

    数据库(Oracle+SQL) 学习笔记

    - `[]` 表示括号中的选项可以选择也可以不选。 - `()` 表示括号中的内容必须出现,并且括号内的各个选项可以有多个。 - SQL 在不同数据库系统中的语法存在差异,例如 `AUTO_INCREMENT` 在 MySQL 中使用,而 `...

    一个win32下的ARM开源编译器

    pre-UAL syntax does not specify the "s" (flag update) in the opcodes for arithmetic operations involving the low set of registers (r0-r7). For example: pre-UAL Syntax | UAL Syntax ;Note -----------...

    微软内部资料-SQL性能优化5

    A qualified operation is one that affects only specific rows that satisfy the conditions of a WHERE clause, as opposed to accessing the whole table. An index can have multiple node levels An index ...

    Delphi7.1 Update

    even when all of the details are deleted if the detail table was previously cloned (Quality Central 5646). * In some cases, records may disappear from a nested TClientDataset after performing edits, ...

    SAP BW Tables

    **Purpose:** This table lists all available update rules, which specify how data is transformed and loaded into SAP BW. **Use Cases:** - Choosing the appropriate update rule for a given data source. ...

    SQL语法大全

    用 rs("别名") 获取统的计值,其它函数运用同上。 (5) 数据表的建立和删除: CREATE TABLE 数据表名称(字段1 类型1(长度),字段2 类型2(长度) …… ) 例:CREATE TABLE tab01(name varchar(50),datetime default ...

    微软内部资料-SQL性能优化3

    Another type of table lock is a schema stability lock (Sch-S) and is compatible with all table locks except the schema modification lock (Sch-M). The schema modification lock (Sch-M) is incompatible ...

    Oracle sqldeveloper without jdk (win+linux)

    You may still update the column with an explicit UPDATE statement referencing the SQL UNISTR function. - Bug 4924518: Only the SQL Worksheet statement input area (code editor) uses a configurable ...

    MySql存储过程编程.chm

    Tuning DML (INSERT, UPDATE, DELETE) Section 21.6. Conclusion Chapter 22. Optimizing Stored Program Code Section 22.1. Performance Characteristics of Stored Programs Section 22.2. How Fast Is ...

    SSD7 选择题。Multiple-Choice

    (b) the name of the table, the names of the table's attributes, the data types of the table's attributes, the formats of the table's attributes, and the maximum number of rows that the table can have...

    RxLib控件包内含RxGIF,全部源码及DEMO

    with the DisplayNames of all indexes available for the table it's assigned to. TBDEItems, TDatabaseItems, TTableItems are lists populated by the corresponding BDE information (database list, table ...

    SQL,SQL命令大全

    -- statements when all conditions are false END ``` #### CASE - **功能**:多条件判断语句。 - **语法示例**: ```sql UPDATE employee SET e_wage = CASE WHEN job_level = '1' THEN e_wage * 1.08 ...

    k7 SRIO参考例程

    Core name: Xilinx LogiCORE Serial RapidIO Version: 5.5 ... - Switch Route Table Destination ID Limit CAR (offset 0x34) - Core does not have functionality to enable the user to drop...

    Radmin自动登录器v3.0-多国语言绿色版-Release1-20150615

    使用前请将Radmin Viewer 3.5的Radmin.exe文件直接拷贝到该目录中,其它Radmin Viewer 3.x版本也可以,中文版、英文版均可; 请设置防火墙允许Radmin.exe和RadminM.exe(仅扫描功能用)访问网络; 若要用到聊天、...

Global site tag (gtag.js) - Google Analytics