2024年3月20日发(作者:)
1. 基本类型:
a) Char(n):固定长度,指定长度n;
b) Varchar(n):可变长度,指定最大长度n;
c) Int:整数类型;
d) Smallint:小整数类型;
e) Numeric(p,d):定点数,p是位数(加上一个符号位),d
是精度,小数点右边的位数;
f) Real,double,precision:浮点数与双精度浮点数;
g) Float(n):精度至少为n位的浮点数。
2. 创建关系:create table
a) create table department
(dept_name varchar(20),
Building varchar(15),
Budget numeric(12,2),
Primary key(dept_name));
3. primary key(a1,a2,…….an):primary key声明表示属性
a1,a2,….an构成关系的主码。主码属性必须非空且唯一。
4. foreign key(b1,b2,…….bn)references table1:foreign key
声明表示关系中任意元组在属性(b1,b2,……bn)上的取值
必须对应于(在…之中)关系table1中某元组在主码属性
上的取。
5. 数据加载:insert
insert into table1
values(a1,a2,….an);
6. 删除元组:delete
delete from table1 删除student中符合谓词p1的
where p1 元组
7. 更新:update
update instructor
set salary=salary*1.05
where salary<70000
(update instructor
set salary =case
when salary<= then salary*1.05
else salary*1.03
end)
8. case语句的一般格式:
case
when p1 then r1
when p2 then r2
…..
when pn then rn
else r0
end


发布评论