zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    关于UI设计的文章汇总
    Linq 中不爽之处
    难题autoconf、automake、libtool
    静态构造函数线程安全的几个版本[转载]
    Window Live Writer
    Guid、Int、BigInt编号的速度和存储空间的比较
    MVP模式中的P和V关系
    LR 剖析器
    快速软件开发 学习笔记 之七
    快速软件开发 学习笔记 之六
  • 原文地址:https://www.cnblogs.com/stu-jyj3621/p/13868136.html
Copyright © 2011-2022 走看看