PostgreSQL 教程
1. PostgreSQL 教程 2. Linux 上安装 PostgreSQL 3. Windows 上安装 PostgreSQL 4. Mac OS 上安装 PostgreSQL 5. PostgreSQL 语法 6. PostgreSQL 数据类型 7. PostgreSQL 创建数据库 8. PostgreSQL 选择数据库 9. PostgreSQL 删除数据库 10. PostgreSQL 创建表格 11. PostgreSQL 删除表格 12. PostgreSQL 模式(SCHEMA) 13. PostgreSQL INSERT INTO 语句 14. PostgreSQL SELECT 语句 15. PostgreSQL 运算符 16. PostgreSQL 表达式 17. PostgreSQL WHERE 子句 18. PostgreSQL AND & OR 运算符 19. PostgreSQL UPDATE 语句 20. PostgreSQL DELETE 语句 21. PostgreSQL LIKE 子句 22. PostgreSQL LIMIT 子句 23. PostgreSQL ORDER BY 语句 24. PostgreSQL GROUP BY 语句 25. PostgreSQL WITH 子句 26. PostgreSQL HAVING 子句 27. PostgreSQL DISTINCT 关键字 28. PostgreSQL 约束 29. PostgreSQL 连接(JOIN) 30. PostgreSQL UNION 操作符 31. PostgreSQL NULL 值 32. PostgreSQL 别名 33. PostgreSQL 触发器 34. PostgreSQL 索引 35. PostgreSQL ALTER TABLE 命令 36. PostgreSQL TRUNCATE TABLE 37. PostgreSQL View(视图) 38. PostgreSQL TRANSACTION(事务) 39. PostgreSQL LOCK(锁) 40. PostgreSQL 子查询 41. PostgreSQL AUTO INCREMENT(自动增长) 42. PostgreSQL PRIVILEGES(权限) 43. PostgreSQL 时间/日期函数和操作符 44. PostgreSQL 常用函数

PostgreSQL 选择数据库

PostgreSQL 选择数据库

上一章节我们讲了如何创建数据库,接下来我们来讨论如何去选择我们创建的数据库。

数据库的命令窗口

PostgreSQL 命令窗口中,我们可以命令提示符后面输入 SQL 语句:

postgres=#

使用 \l 用于查看已经存在的数据库:

postgres=# \l

                             List of databases

   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges   

-----------+----------+----------+---------+-------+-----------------------

 postgres  | postgres | UTF8     | C       | C     | 

 db  | postgres | UTF8     | C       | C     | 

 template0 | postgres | UTF8     | C       | C     | =c/postgres          +

           |          |          |         |       | postgres=CTc/postgres

 template1 | postgres | UTF8     | C       | C     | =c/postgres          +

           |          |          |         |       | postgres=CTc/postgres

(4 rows)

接下来我们可以使用 \c + 数据库名 来进入数据库:

postgres=# \c db

You are now connected to database "db" as user "postgres".

db=# 

系统命令行窗口

在系统的命令行查看,我么可以在连接数据库后面添加数据库名来选择数据库:

$ psql -h localhost -p 5432 -U postgress db

Password for user postgress: ****

psql (11.3)

Type "help" for help.

You are now connected to database "db" as user "postgres".

db=# 

pgAdmin 工具

pgAdmin 工具更简单了,直接点击数据库选择就好了,还可以查看一些数据库额外的信息: