database-note-2

mac2024-04-18  36

SQL

DDL

删除表、数据

12# 删除表结构和数据drop table 表名; 12# 保留表结构,可筛选条件delete from 表名;

DML

DML: data-manipulation language

定义

提供操作数据的能力,包括增删查改。

查询

定义

$select \quad A_1, A_2, …, A_3 \quad from \quad r_1, r_2, …, r_m \quad where \quad P$

$A_i$ 表示属性集$r_i$ 表示关系表$P$ 表示查询条件,谓词(predicate)

1select 列名_1,列名_2, ... from 表明 where 筛选条件;

关键字

distinct:去除重复record,all:选取全部可重复record*:通配符,选取全部属性

from

操作多个表时,对这几个表的属性集做笛卡尔连接。

Natural Join

在两张表中存在共有取值的record连接起来。

1select * from A natural join B;

重命名

1select ID, name, salary/12 as monthly_salary from teacher;

模糊匹配

模糊匹配使用 like

%: *___: {3}___%: {3,}

排序

asc: 升序,desc: 降序多个条件表示,在前一个条件无法区分时,下一个条件作为评判标准。
最新回复(0)