• PSQL 指令下完後面必須加 ;

  • 查詢多少DB

      psql -l
    
  • 進入 DB

      psql myDB
    
  • 建立Database (範例: 建立一個Encoding為EUC_TW的DB)

      createdb aaa -E EUC_TW
    
  • 刪除資料庫

      dropdb myDB
    
  • 查看DB內有多少table

      myDB=# \dt
    
  • 查看table的欄位資料型態

      \d tableName
    

範例表格 (Store_info)

Store_name Sales Date
Los 1500 Jan-05-1999
San 250 Jan-07-1999
Los 300 Jan-08-1999
Boston 700 Jan-08-1999
  • 查詢欄位全部值
    select "欄位名" from "表格名"

    select Store_name from Store_info
    
Store_name
Los
San
Los
Boston
  • 查詢欄位種類值 (篩選重複名稱)
    select distinct "欄位名" from "表格名"

    select distinct Store_name from Store_info
    
Store_name
Los
San
Boston

results matching ""

    No results matching ""