网站编辑器做段落空格,品牌定位,做笑话网站,wordpress占用资源大3.3.DML
DML 是 “Data Manipulation Language”#xff08;数据操作语言#xff09;的缩写#xff0c;在数据库管理系统#xff08;DBMS#xff09;中用来处理已存在的数据库中的数据。
它主要包含用于插入#xff08;INSERT#xff09;、更新#xff08;UPDATE数据操作语言的缩写在数据库管理系统DBMS中用来处理已存在的数据库中的数据。
它主要包含用于插入INSERT、更新UPDATE、删除DELETE
以及查询SELECT虽然 SELECT 有时被归类为其自己的类别即数据查询语言DQL数据库记录的SQL命令。
这些操作允许用户修改存储在表中的数据。 3.3.0.测试用表
/*Navicat Premium Data TransferSource Server : 00localSource Server Type : MySQLSource Server Version : 80016 (8.0.16)Source Host : localhost:3306Source Schema : a1Target Server Type : MySQLTarget Server Version : 80016 (8.0.16)File Encoding : 65001Date: 26/10/2024 09:48:54
*/SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS 0;-- ----------------------------
-- Table structure for student
-- ----------------------------
DROP TABLE IF EXISTS student;
CREATE TABLE student (stu_id int(11) NOT NULL AUTO_INCREMENT COMMENT 学生主键#自增长,stu_name varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 学生姓名,stu_sex tinyint(4) NULL DEFAULT NULL COMMENT 学生性别#男1, 女0,stu_birth date NULL DEFAULT NULL COMMENT 学生生日,stu_weight double NULL DEFAULT NULL COMMENT 学生体重,stu_height int(11) NULL DEFAULT NULL COMMENT 学生身高,team_id int(11) NULL DEFAULT NULL COMMENT 团队外键,stu_info varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 备注,PRIMARY KEY (stu_id) USING BTREE
) ENGINE InnoDB AUTO_INCREMENT 15 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT student 学生 ROW_FORMAT Dynamic;-- ----------------------------
-- Records of student
-- ----------------------------
INSERT INTO student VALUES (1, 刘首一, 1, 2001-07-20, 61.3, 179, 1, );
INSERT INTO student VALUES (2, 王小二, 1, 2004-03-05, 59.6, 182, 1, 热爱编程的计算机科学专业新生);
INSERT INTO student VALUES (3, 李小三, 0, 2002-12-13, 48.5, 168, 1, 对历史非常感兴趣);
INSERT INTO student VALUES (4, 赵小四, 1, 2004-05-29, 66.2, 180, 1, 对未来充满好奇的艺术系学生);
INSERT INTO student VALUES (5, 武五五, 0, 2005-05-05, NULL, NULL, NULL, NULL);
INSERT INTO student VALUES (6, 刘小六, 1, 2001-08-19, 56.6, 166, 3, 热衷于探索科学的奥秘);
INSERT INTO student VALUES (7, 闩小七, 1, 2004-03-05, 57.4, 172, 1, 对文学有着浓厚的兴趣);
INSERT INTO student VALUES (8, 赵静子, 0, 2004-11-26, 50, 156, 3, NULL);
INSERT INTO student VALUES (9, 张不开, 0, 2002-07-06, 60, 176, 2, null);
INSERT INTO student VALUES (10, 小金刚, 1, NULL, 59.6, 185, 2, (Null));
INSERT INTO student VALUES (11, 吴琼小, 0, 2005-07-22, 49.2, 166, 1, NULL);
INSERT INTO student VALUES (12, 张崖五小, NULL, 2005-01-08, 70.8, 182, 1, 一个电子游戏设计专业的新生);
INSERT INTO student VALUES (13, 何叶小露, 0, 2003-06-11, 44.5, 168, NULL, 一个喜欢旅行和摄影的人);
INSERT INTO student VALUES (14, 小沈阳, 1, NULL, 66.9, 173, 3, 热爱音乐);-- ----------------------------
-- Table structure for team
-- ----------------------------
DROP TABLE IF EXISTS team;
CREATE TABLE team (team_id int(11) NOT NULL AUTO_INCREMENT COMMENT 团队主键#自增长,team_title varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT 团队名称,stu_count int(11) NULL DEFAULT NULL COMMENT 成员数量,PRIMARY KEY (team_id) USING BTREE
) ENGINE InnoDB AUTO_INCREMENT 4 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT team 团队 ROW_FORMAT Dynamic;-- ----------------------------
-- Records of team
-- ----------------------------
INSERT INTO team VALUES (1, 科技组, 7);
INSERT INTO team VALUES (2, 龙虎舞狮, 2);
INSERT INTO team VALUES (3, 玄武岩合唱团, 3);
INSERT INTO team VALUES (4, 考古兴趣班, NULL);SET FOREIGN_KEY_CHECKS 1;3.3.1.基本语法
3.3.1.1.查询表中的记录
语法 : select 字段1, 字段2,... from 表名
-- 查询 全部记录 全部字段
select stu_id, stu_name, stu_sex, stu_birth, stu_weight, stu_height, team_id, stu_info
from student;-- 查询部分字段
select stu_name, stu_sex, stu_birth
from student;-- 根据条件查询部分记录
select stu_id, stu_name, stu_sex, stu_birth, stu_weight, stu_height, team_id, stu_info
from student
where stu_id 1;3.3.1.2.增加一条
语法 : insert into 表名( 字段1, 字段2,... ) values( 值1, 值2, ... )
-- 插入全字段数据
insert into student(stu_id, stu_name, stu_sex, stu_birth, stu_weight, stu_height, team_id, stu_info)
values ( 20, 刘小翠, 0 , 2003-09-02 , 56.7 , 168 , 1, 学霸);-- 插入全字段数据, 字段可以省略
insert into student
values ( 21, 马小花, 0 , 2004-02-12 , 52.7 , 158 , 2, 喜欢运动);-- 插入部分字段数据
insert into student(stu_id, stu_name, stu_sex)
values ( 22, 肖火火, 1);-- 插入部分字段数据, id自增
insert into student(stu_name, stu_sex)
values ( 叶发, 1);3.3.1.3.增加多条
语法 : insert into 表名( 字段1, 字段2 ) values( 值1, 值2 ), ( 值1, 值2 ), ( 值1, 值2 )
-- 插入多条
insert into student( stu_name, stu_sex, stu_birth )
values (紫川禾, 1, 2002-09-08), (帝木, 0, 2001-06-09), (斯特森, 1, 2001-10-11);3.3.1.4.从另一张表中导入数据
语法 : insert into 导入表名 ( 字段1, 字段2, ... ) select 字段1, 字段2, ... from 导出表名
先创建 stu 表并增加 字段
-- 创建表
create table stu(id int primary key auto_increment,name varchar(20) not null,sex boolean not null,birth date
);从 student表中读取数据 导入到 stu表 中,
其中 sex 写成 固定的 1( 当然 这个字段也可以读取来)
insert into stu(name, sex, birth)
select stu_name, 1, stu_birth
from student
where stu_birth is not null;3.3.1.5.修改记录
语法 : update 表名 set 字段1 值1, 字段2 值2 where 条件
注意没有条件, 会修改表中所有记录
主键可以修改, 但通常不要这样做
-- 修改全部属性
update student
setstu_name 刘小光,stu_sex 1,stu_birth 2000-03-22,stu_weight 65.6,stu_height 178,team_id 2,stu_info 不喜欢运动
where stu_id 20;-- 只修改总分属性
update student
setstu_info 喜欢写作
where stu_id 20;3.3.1.6.删除记录
语法 : delete from 表名 where 条件
不加where 条件 会删除表中全部的记录
-- 删除
delete from student where stu_id 20;
文章转载自: http://www.morning.tbksk.cn.gov.cn.tbksk.cn http://www.morning.yxwrr.cn.gov.cn.yxwrr.cn http://www.morning.kwwkm.cn.gov.cn.kwwkm.cn http://www.morning.rpzth.cn.gov.cn.rpzth.cn http://www.morning.lgcqj.cn.gov.cn.lgcqj.cn http://www.morning.drrt.cn.gov.cn.drrt.cn http://www.morning.ffwrq.cn.gov.cn.ffwrq.cn http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn http://www.morning.qhvah.cn.gov.cn.qhvah.cn http://www.morning.dfffm.cn.gov.cn.dfffm.cn http://www.morning.bzfwn.cn.gov.cn.bzfwn.cn http://www.morning.tkryt.cn.gov.cn.tkryt.cn http://www.morning.jjsxh.cn.gov.cn.jjsxh.cn http://www.morning.gqfbh.cn.gov.cn.gqfbh.cn http://www.morning.sooong.com.gov.cn.sooong.com http://www.morning.wqpsf.cn.gov.cn.wqpsf.cn http://www.morning.kfbth.cn.gov.cn.kfbth.cn http://www.morning.jbpdk.cn.gov.cn.jbpdk.cn http://www.morning.trrd.cn.gov.cn.trrd.cn http://www.morning.bsrqy.cn.gov.cn.bsrqy.cn http://www.morning.pbdnj.cn.gov.cn.pbdnj.cn http://www.morning.lwnb.cn.gov.cn.lwnb.cn http://www.morning.yxwcj.cn.gov.cn.yxwcj.cn http://www.morning.kqkmx.cn.gov.cn.kqkmx.cn http://www.morning.stxg.cn.gov.cn.stxg.cn http://www.morning.grnhb.cn.gov.cn.grnhb.cn http://www.morning.gdpai.com.cn.gov.cn.gdpai.com.cn http://www.morning.yrbq.cn.gov.cn.yrbq.cn http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn http://www.morning.hqnsf.cn.gov.cn.hqnsf.cn http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn http://www.morning.drwpn.cn.gov.cn.drwpn.cn http://www.morning.wbrf.cn.gov.cn.wbrf.cn http://www.morning.lmmkf.cn.gov.cn.lmmkf.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.ptmch.com.gov.cn.ptmch.com http://www.morning.ydzly.cn.gov.cn.ydzly.cn http://www.morning.phechi.com.gov.cn.phechi.com http://www.morning.mtktn.cn.gov.cn.mtktn.cn http://www.morning.wtdyq.cn.gov.cn.wtdyq.cn http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn http://www.morning.zlff.cn.gov.cn.zlff.cn http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn http://www.morning.fnczn.cn.gov.cn.fnczn.cn http://www.morning.hjwxm.cn.gov.cn.hjwxm.cn http://www.morning.jkdtz.cn.gov.cn.jkdtz.cn http://www.morning.mxxsq.cn.gov.cn.mxxsq.cn http://www.morning.tgxrm.cn.gov.cn.tgxrm.cn http://www.morning.sgnxl.cn.gov.cn.sgnxl.cn http://www.morning.ykshx.cn.gov.cn.ykshx.cn http://www.morning.clndl.cn.gov.cn.clndl.cn http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn http://www.morning.tnwwl.cn.gov.cn.tnwwl.cn http://www.morning.rdpps.cn.gov.cn.rdpps.cn http://www.morning.nknt.cn.gov.cn.nknt.cn http://www.morning.gcysq.cn.gov.cn.gcysq.cn http://www.morning.pflry.cn.gov.cn.pflry.cn http://www.morning.xbzfz.cn.gov.cn.xbzfz.cn http://www.morning.bchhr.cn.gov.cn.bchhr.cn http://www.morning.zdbfl.cn.gov.cn.zdbfl.cn http://www.morning.shuangxizhongxin.cn.gov.cn.shuangxizhongxin.cn http://www.morning.dlhxj.cn.gov.cn.dlhxj.cn http://www.morning.cwjsz.cn.gov.cn.cwjsz.cn http://www.morning.drcnn.cn.gov.cn.drcnn.cn http://www.morning.jcxgr.cn.gov.cn.jcxgr.cn http://www.morning.ldnrf.cn.gov.cn.ldnrf.cn http://www.morning.lnnc.cn.gov.cn.lnnc.cn http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn http://www.morning.mgwpy.cn.gov.cn.mgwpy.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.ryxyz.cn.gov.cn.ryxyz.cn http://www.morning.tmfhx.cn.gov.cn.tmfhx.cn http://www.morning.yrngx.cn.gov.cn.yrngx.cn http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn http://www.morning.gypcr.cn.gov.cn.gypcr.cn http://www.morning.nrjr.cn.gov.cn.nrjr.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.lxdbn.cn.gov.cn.lxdbn.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.jrplk.cn.gov.cn.jrplk.cn