数据定义
基本数据类型
- char(n)定长度字符串
- varchar(n)可变长度字符串
- int整数
- smallint小整数
- numeric(p,d)定点数,精度由用户指定,p位数字,其中d位数字在小数点右边
- real, double precision浮点数,双精度浮点数
- float(n)精度至少为n的浮点数
| 1 | create table department | 
查询的基本结构
| 1 | select dept_name from instructor; | 
自然链接
| 1 | select name, title | 
更名运算
将长的关系名替换成短的,这样在其他的查询中方便使用1
2
3select name as instructor_name, course_id
from instructor, teaches
where instructor.ID = teaches.ID
字符串运算
- %匹配任意字符串
- _匹配任意一个字符
- \转移字符
集合运算
并运算
| 1 | (select course_id from section where semester = 'Fall' and year = 2009) | 
交运算
intersect
差运算
except
聚集函数
- avg
- min
- max
- sum
- count
数据库修改
删除
| 1 | delete from t | 
插入
| 1 | insert into course(course_id, title, dept_name, credits) | 
更新
| 1 | update instructor |