【学习笔记】DML语法
收藏回复举报
回复仅回复人和楼主可见
【学习笔记】DML语法
发表于2023-11-10 08:10:54
0 查看

DML是Data Manipulation Language的缩写,通常用于对数据库表中的数据进行操作,例如增删改查。

// 创建表
create table report(name char, score int);
// 插入数据
insert into report(name, score) values (‘a’, 85), (‘b’, 80), (‘c’, 90);
// 查询数据
select * from report;
select count(*) from report;  // 查询数据条数
select name, score from report order by score desc;  // 按score字段降序排列

// 更改数据
update report set score = score + 5;  // 对所有元组的score字段+5
// copy语句在表和文件之间拷贝数据
copy report to ‘/home/omm/report.sql’;
more /home/omm/report.sql  // 终端命令查看拷贝后的文件

// copy to:从表复制到文件 copy from: 从文件复制到表

// 删除数据
delete from report where score < 90;  // 删除score小于90的数据
truncate table report;  // 删除所有记录

本帖最后由 匿名用户 于 2025/04/01 18:45:49 编辑

我要发帖子