mysql基本操作之表的增删改(二)

首先我们创建一张用户表

 -- 创建表
    create table user(
        id int primary key  auto_increment,
        name varchar(10),
        age tinyint
    )charset utf8 comment '用户表';

然后往表里插入数据

-- 插入数据
    insert  into  user(id,name,age)value(2,'chris',21);
    -- 或可以这么写
    insert into user value (1,'jamal',18);
    -- 也可以批量插入
    insert into user values(3,'durant',30),
                             (4,'wall',21);

删除表中的某一行数据

-- 删除表中的id为1数据
    delete from user where id = 1;
    -- 删除表中name为durant的数据
    delete from user where name = 'durant';
    -- 删除表中age为21的数据
    delete  from user where age = 21;

更新表中的某一行数据

 -- 更新表中id为2,名字改为yongjar
    update user set name = 'yongjar' where  id = 2;
    -- 更新表中名字为wall,年龄改为31
    update user set age = 21 where  name = 'wall';

猜你喜欢

转载自www.cnblogs.com/jamal/p/10958037.html
今日推荐