• 数据库基本操作--DML


    基本介绍

    DML是指数据操作语言,英文全称是Data Manipulation Language,用来对数据库中表的数据记录进行更新。

    关键字

    • 插入 insert
    • 删除 delete
    • 更新 update
    插入

    语法格式:

    //向表中插入某些列的数据
    insert into 表(列名1,列名2,...)values (值1,值2, ...)
    insert into 表 values(值1,值2,值3....) //向表中插入所有列
    
    -- 将所有学生的地址修改为重庆 
    update student set address = '重庆’; 
    
    -- 讲id为1004的学生的地址修改为北京 
    update student set address = '北京' where id = 1004 
    
    -- 讲id为1005的学生的地址修改为北京,成绩修成绩修改为100 
    update student set address = '广州',score=100 where id = 1005
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    删除

    语法格式:

    delete from 表名 [where 条件];//不加 where 就是清空表
    truncate table 表名 或者 truncate 表名
    
    -- 1.删除sid为1004的学生数据
    delete from student where sid  = 1004;
    -- 2.删除表所有数据
    delete from student;
    -- 3.清空表数据
    truncate table student;
    truncate student;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    注意:delete和truncate原理不同,delete只删除内容,而truncate类似于drop table,可以理解为是将整个表删除,然后再创建该表

    更新

    语法格式:

    update 表名 set 字段名=值,字段名=值...; //不要忘了字段之间的逗号
    update 表名 set 字段名=值,字段名=值... where 条件;
    --例子:
    -- 将所有学生的地址修改为重庆 
    update student set address = '重庆’; 
    
    -- 讲id为1004的学生的地址修改为北京 
    update student set address = '北京' where id = 1004 
    
    -- 讲id为1005的学生的地址修改为北京,成绩修成绩修改为100 
    update student set address = '广州',score=100 where id = 1005
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    信息论基础第二章部分习题
    正则匹配以XXX开头的,XXX结束的
    Databend 开源周报 #69
    JDK8的 ConcurrentHashMap 源码分析
    在线表格 循环替换 脚本
    AI原生技术分享活动:引领智能科技新浪潮
    优化yarn在任务执行时核数把控不准确的问题
    Open3D(C++) SVD分解求两个点云的变换矩阵
    一个 MySQL 隐式转换的坑,差点把服务器整崩溃了
    敬老院管理
  • 原文地址:https://blog.csdn.net/m0_73282576/article/details/133419441