MySQL更新UPDATA的使用

语法:UPDATE 表名 SET 列名=值 [WHERE 条件语句];

 

mysql> SELECT * FROM student_info;

+------+---------+

| age  | name    |

+------+---------+

|   12 | Lili    |

|   27 | Jack    |

|   25 | Rose    |

|   25 | Ann     |

|   26 | Mark    |

|   68 | Bill    |

|   16 | James   |

|   20 | Fred    |

|    8 | Gary    |

|   22 | Martin  |

|   35 | Charles |

|   31 | Joseph  |

|   49 | Henry   |

|   57 | Mike    |

| NULL | Bob     |

+------+---------+

15 rows in set (0.00 sec)



mysql>

 

 

# 将所有age都置0


mysql> UPDATE student_info SET age=0; Query OK, 15 rows affected (0.04 sec) Rows matched: 15 Changed: 15 Warnings: 0 mysql> SELECT * FROM student_info; +------+---------+ | age | name | +------+---------+ | 0 | Lili | | 0 | Jack | | 0 | Rose | | 0 | Ann | | 0 | Mark | | 0 | Bill | | 0 | James | | 0 | Fred | | 0 | Gary | | 0 | Martin | | 0 | Charles | | 0 | Joseph | | 0 | Henry | | 0 | Mike | | 0 | Bob | +------+---------+ 15 rows in set (0.00 sec) mysql>
# 将名为Rose的年龄改为26


mysql> UPDATE student_info SET age=26 WHERE name='Rose'; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM student_info; +------+---------+ | age | name | +------+---------+ | 0 | Lili | | 0 | Jack | | 26 | Rose | | 0 | Ann | | 0 | Mark | | 0 | Bill | | 0 | James | | 0 | Fred | | 0 | Gary | | 0 | Martin | | 0 | Charles | | 0 | Joseph | | 0 | Henry | | 0 | Mike | | 0 | Bob | +------+---------+ 15 rows in set (0.00 sec) mysql>

 

你可能感兴趣的:(mysql)