1.數據庫update查詢
update 表名稱 set 字段名+where+字段名
例如 posts表
id | title | author |
1 | foolish | 豬八戒 |
2 | stupid | 孫悟空 |
update posts set title="clever" where author="孫悟空"
結果如下:
id | title | author |
1 | foolish | 豬八戒 |
2 | clever | 孫悟空 |
ruby中的應用方法如:
Post.update("title="clever","author='孫悟空'")
update_all用法同上,
2.delete數據庫中用法
delete 表名(刪除表)delete*from 表名(刪除表)
delete * from 表名 where+ 條件
例如:
delete *from posts where author="豬八戒"
結果如下
id | title | author |
1 | clever | 孫悟空 |
ruby中的用法
Post.delete(條件)
Post.delete_all(條件)
用法與update及其相似