- PostgreSQL 教程
- PostgreSQL - 首頁
- PostgreSQL - 概述
- PostgreSQL - 環境設定
- PostgreSQL - 語法
- PostgreSQL - 資料型別
- PostgreSQL - 建立資料庫
- PostgreSQL - 選擇資料庫
- PostgreSQL - 刪除資料庫
- PostgreSQL - 建立表
- PostgreSQL - 刪除表
- PostgreSQL - 模式
- PostgreSQL - 插入查詢
- PostgreSQL - 選擇查詢
- PostgreSQL - 運算子
- PostgreSQL - 表示式
- PostgreSQL - WHERE 子句
- PostgreSQL - AND & OR 子句
- PostgreSQL - 更新查詢
- PostgreSQL - 刪除查詢
- PostgreSQL - LIKE 子句
- PostgreSQL - LIMIT 子句
- PostgreSQL - ORDER BY 子句
- PostgreSQL - GROUP BY
- PostgreSQL - WITH 子句
- PostgreSQL - HAVING 子句
- PostgreSQL - DISTINCT 關鍵字
- 高階 PostgreSQL
- PostgreSQL - 約束
- PostgreSQL - 聯接
- PostgreSQL - UNION 子句
- PostgreSQL - NULL 值
- PostgreSQL - 別名語法
- PostgreSQL - 觸發器
- PostgreSQL - 索引
- PostgreSQL - ALTER TABLE 命令
- 截斷表命令
- PostgreSQL - 檢視
- PostgreSQL - 事務
- PostgreSQL - 鎖
- PostgreSQL - 子查詢
- PostgreSQL - 自動遞增
- PostgreSQL - 許可權
- 日期/時間函式和運算子
- PostgreSQL - 函式
- PostgreSQL - 有用函式
- PostgreSQL 介面
- PostgreSQL - C/C++
- PostgreSQL - Java
- PostgreSQL - PHP
- PostgreSQL - Perl
- PostgreSQL - Python
- PostgreSQL 有用資源
- PostgreSQL - 快速指南
- PostgreSQL - 有用資源
- PostgreSQL - 討論
PostgreSQL - 選擇資料庫
本章介紹了訪問資料庫的各種方法。假設我們已經在上一章中建立了一個數據庫。您可以使用以下任何一種方法選擇資料庫:
- 資料庫 SQL 提示符
- 作業系統命令提示符
資料庫 SQL 提示符
假設您已經啟動了 PostgreSQL 客戶端,並且您已到達以下 SQL 提示符:
postgres=#
您可以使用\l(即反斜槓 el 命令)檢查可用的資料庫列表,如下所示:
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | C | C |
(4 rows)
postgres-#
現在,鍵入以下命令連線/選擇所需的資料庫;這裡,我們將連線到testdb資料庫。
postgres=# \c testdb; psql (9.2.4) Type "help" for help. You are now connected to database "testdb" as user "postgres". testdb=#
作業系統命令提示符
您可以在登入資料庫時從命令提示符本身選擇您的資料庫。以下是一個簡單的示例:
psql -h localhost -p 5432 -U postgress testdb Password for user postgress: **** psql (9.2.4) Type "help" for help. You are now connected to database "testdb" as user "postgres". testdb=#
您現在已登入到 PostgreSQL testdb 並準備在 testdb 中執行您的命令。要退出資料庫,可以使用命令 \q。
廣告