• Mysql 2 —— 最基本的增删改查


    添加值的操作

    1.往哪张表添加行?2.给哪几列添加值?3.分别是什么值?

    insert into class
    (id,sname,gender,company,salary,fanbu)
    values
    (1,'張三','男','百度',8888.67,234);

    mysql> insert into class
    -> (sname,gender,salary)
    -> values
    -> ('刀鋒','男',8765.43);

    id在上例中虽然没有插入,但是id是自增型,因此值为2,
    回头再来看,插入所有列的情况,如果插入所有列,则可以不声明待插入的列。
    即如果不声明插入的列,则理解为一次插入所有列

    insert into class
    values
    (3,'李四','男','新浪',8788.67,204);

    提醒不要犯如下错误,
    有同学认为id是自增型的,插入时不必为其赋值
    insert into class
    values
    ('李四','男','新浪',8788.67,204);///错

    输入多个数据
    insert into class
    (sname,gender,company,salary)
    values
    ('刘备','男','皇室成员',15.28),
    ('孙策','男','江东成员',56.32),
    ('曹操','男','宦官后代',86.52);

    改表格中数据
    update 改的要素
    改哪几张表: update
    改哪几行: gender, company
    改成什么值: '女','千'

    mysql> update class
    -> set fanbu = 123
    -> where id=6;

    mysql> update class set gender ='',fanbu='212' where sname = '孙策';
    如果有两个'孙策',就改两个

    改性别为男并且工资c>8000的用户
    update class set fanbu=159 where gender='男' and salary>8000;

    删除就是指删除整行,不存在删除一行中的某几列
    1.删哪张表的数据:class
    2.删哪几行:where expression

    delete from class where salary>8800;

    查询三要素
    1.查那张表 class
    2.查那些列

    select sname,company,salary from class where id=6;

    展示数据:
    mysql> select * from newstu;

    转载请注明出处:https://www.cnblogs.com/stu-jyj3621
  • 相关阅读:
    编程实现折半法查找
    浅谈C++多态性
    纯虚函数的使用汇总
    虚函数如何实现多态 ?
    重载(overload),覆盖(override),隐藏(hide)的区别
    Qt入门之常用Qt标准对话框之QMessageBox
    Qt5学习笔记(5)——列表框QListWidget类
    python 文件的方法
    python---while循环
    python ---strip()方法,split()方法,删除字符串开头或结尾,字符串分隔
  • 原文地址:https://www.cnblogs.com/stu-jyj3621/p/13868136.html
Copyright © 2020-2023  润新知