MySQL 8 update语句更新数据表里边的数据

数据重新补充

这里使用alter table Bookbought.bookuser add userage INT after userphone;为用户表bookuseruserphone列后边添加一个类型为INT的新列userage
使用alter table Bookbought.bookuser add sex varchar(6) after userage ;为用户表bookuseruserage 列后边添加一个类型为INT的新列sex
MySQL 8 update语句更新数据表里边的数据_第1张图片

describe Bookbought.bookuser;查看数据库中的表结构,可以查看插入之后的数据字段。
MySQL 8 update语句更新数据表里边的数据_第2张图片

update更新数据

使用格式如下:

update 数据库.表名 
set 字段 = 字段值  
where 判断条件

使用下方的update语句把以前没有填上去的年龄填上去。

update Bookbought.bookuser set userage = 31,sex='male' where id = 1;
update Bookbought.bookuser set userage = 32,sex='female' where id = 2;
update Bookbought.bookuser set userage = 33,sex='male' where id = 3;
update Bookbought.bookuser set userage = 34,sex='female' where id = 4;
update Bookbought.bookuser set userage = 35,sex='male' where id = 5;
update Bookbought.bookuser set userage = 36,sex='male' where id = 6;
update Bookbought.bookuser set userage = 37,sex='female' where id = 7;
update Bookbought.bookuser set userage = 38,sex='male' where id = 8;
update Bookbought.bookuser set userage = 45,sex='male' where id = 9;
update Bookbought.bookuser set userage = 50,sex='female' where id = 10;

MySQL 8 update语句更新数据表里边的数据_第3张图片

你可能感兴趣的:(MySQL学习,mysql,数据库)