日期和时间类型
-
date: 'yyyy-mm-dd' -
time: 'HH-MM-SS'-
time with timezone: 保存时区信息
-
-
timestamp: 'yyyy-mm-dd HH-MM-SS.mmtimestamp with timezone
-
cast string as t:将以符合格式的字符串string转化为t类型(t可以为time,date,timestamp) -
extract(field from d):从time或date值d中提取出单独域(field可以为year,month,day,hour,minute,second,timezone_hour,timezone_minute)
默认值
create table student(
ID varchar(5) primary key,
name varchar(20) not null,
dept_name varchar(20),
tot_cred numeric(3, 0) default 0);
创建索引
索引:创建在关系的属性上的一种数据结构,允许数据库系统高效地找到关系中那些在索引属性上取得给定值的元组,而不需要扫描关系中的所有元组。
create index studentID_index on student(ID);
大对象类型
-
clob:字符数据的大对象类型(character-large-object) -
blob:二进制数据的大对象类型(binary-large-object)
create table my_files(
book_review clob(10KB),
image blob(10MB),
movie blob(2GB)
);
create table拓展
- 创建与现有表模式相同的表
create table temp_instructor like instructor; - 将查询结果写入新表
create table t1 as (
select *
from instructor
where dept_name = 'Music')
with data;