• mysql 单表下的字段操作


    如下只介绍单表的添加、更新、删除、查询表结构操作,查询数据操作范围太大用单独的篇幅来讲解;

    查看表结构

    desc test_tb;
    

    Insert 插入数据

    插入 = 添加

    为表中指定的字段插入数据

    Create table student(
        id int(4),
        name varchar(20) not null,
        grade float
    );
    
    Insert into test_tb(id,name,grade) values(1,"lisi",98);
    

    不指定字段插入数据

    不指定字段,就相当于每个字段都要填充上值才行;

    Create table student(
        id int(4),
        name varchar(20) not null,
        grade float
    );
    
    Insert into test_tb values(1,"lisi",98);
    # 由于没有指定字段,那么顺序和数量一定得和表中的字段顺序、数量都得一致;
    

    同时插入多条记录

    批量插入

    Create table student(
        id int(4),
        name varchar(20) not null,
        grade float
    );
    
    Insert into test_tb(id,name,grade) values(1,"lisi",98),(2,"wangwu",60),(1,"chenliu",76);
    

    Update 更新数据

    更新Set 字段下全部数据

    Update test_tb Set age=18,sex=1
    

    更新指定条件的数据

    Update test_tb Set age=18,sex=1 where id=1;
    

    Delete 删除数据

    删除全部数据

    Delete from test_tb;
    

    删除指定条件的数据

    Delete from test_tb where id = 1;

  • 相关阅读:
    [考试]20150811
    [考试]20150810
    [随笔]暑假过了,暑假来了
    [考试]20150808
    动态规划大合集II
    [知识点][旧版]C++中的运算符
    NOIP动态规划大合集
    [考试]20150729
    [考试]20150728
    /=============分隔线=============/
  • 原文地址:https://www.cnblogs.com/mysticbinary/p/12865739.html
Copyright © 2020-2023  润新知