mysql更新,修改语句汇总--update set,alter

拼搏现实的明天。 2021-09-23 02:46 608阅读 0赞

update set 语句是mysql最常用的修改和更新语句。







A  update set 与where搭配使用,变更某些记录:

update +表名 +set+ 变更后的信息 +where子句;

例如:








update stu set birth=1988,department=’中文系’ where id=9    and name=’张三’;

注意:如果变更信息后面没有加where子句指定其变更的内容,那么update set语句就会把同字段中的所有信息全部更新,修改。

例如:

mysql> select * from c1score;
+———-+———+
| score | s |
+———-+———+
| 56 | 1 |
| 79 | 2 |
| 91 | 3 |
| 46 | 5 |
| 35 | 6 |
+———-+———+
5 rows in set (0.08 sec)

mysql> update c1score set score=score+8;
Query OK

发表评论

表情:
评论列表 (有 0 条评论,608人围观)

还没有评论,来说两句吧...

相关阅读

    相关 mysql语句update之联合更新

            最近遇到一个小问题,数据库方面的,两张表有主外键关系,其中一个表添加一个字段,在另一个表中是有值的,并把这个字段同步更新到这张表中,说起来有点绕,还是看具体案例