SQL筆記--(5)--[數(shù)據(jù)類型與模式]

日期和時間類型

  1. date: 'yyyy-mm-dd'
  2. time: 'HH-MM-SS'
    • time with timezone: 保存時區(qū)信息
  3. timestamp: 'yyyy-mm-dd HH-MM-SS.mm
    • timestamp with timezone
  4. cast string as t:將以符合格式的字符串string轉(zhuǎn)化為t類型(t可以為time, date, timestamp)
  5. extract(field from d):從timedated中提取出單獨(dú)域(field可以為year, month, day, hour, minute, second, timezone_hour, timezone_minute

默認(rèn)值

create table student(
        ID varchar(5) primary key,  
        name varchar(20) not null, 
        dept_name varchar(20),
        tot_cred numeric(3, 0) default 0);

創(chuàng)建索引

索引:創(chuàng)建在關(guān)系的屬性上的一種數(shù)據(jù)結(jié)構(gòu),允許數(shù)據(jù)庫系統(tǒng)高效地找到關(guān)系中那些在索引屬性上取得給定值的元組,而不需要掃描關(guān)系中的所有元組。

create index studentID_index on student(ID);

大對象類型

  1. clob:字符數(shù)據(jù)的大對象類型(character-large-object
  2. blob:二進(jìn)制數(shù)據(jù)的大對象類型(binary-large-object
create table my_files(
      book_review clob(10KB),
      image blob(10MB),
      movie blob(2GB)
);

create table拓展

  1. 創(chuàng)建與現(xiàn)有表模式相同的表
    create table temp_instructor like instructor;
  2. 將查詢結(jié)果寫入新表
create table t1 as (
            select *
            from instructor
            where dept_name = 'Music')
    with data;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容