日期和時間類型
-
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;