-- DML操作
-- 1.数据的插入
-- 格式1:insert into 表(列名1,列名2,列名3...)values (值1,值2,值3...);
use mybd1;
insert into student(sid,name,gender,age,birth,address,score)
values (1001,'张三','男',18,'2001-12-23','北京',85.5)
;
insert into student(sid,name,gender,age,birth,address,score)
values (1002,'李四','女',19,'2001-12-29','上海',95.5),
(1003,'王五','男',17,'2001-11-23','深圳',100)
;
insert into student(sid) value(1004);
insert into student(sid,name) value(1005,'赵六');
-- 格式2:intsert into 表 values (值1,值2,值3...);
insert into student values(1006,'张华','女',21,'199-01-08','广州',80);
-- 数据修改
-- 格式1:updata 表名 set 字段名=值,字段名=值...;
-- 格式2: updata 表名 set 字段名=值,字段名=值... where 条件;
-- 1.将所有学生的地址修改为重庆
update student set address = '重庆'
-- 2.将id为104的学生的地址修改为北京
update student set address = '北京' where sid = 1004;
update student set address = '上海' where sid > 1004;
-- 3.将id为1005的学生地址修改为北京,成绩修改为100
update student set address = '北京',score = 100 where sid = 1005;
-- 删除数据
-- 格式:delete form 表名 [where 条件];
-- 1.删除sid为1004的学生数据
delete from student where sid = 1004;
-- 2.删除表所有的数据
delete from student;
-- 3.清空表中的数据
truncate table student;
truncate student;
-- 将表删除并创建一个新表
MYSQL数据库操作DML
最新推荐文章于 2023-08-21 15:08:03 发布