PostgreSQL

【PostgreSQL】テーブルの一覧表示・作成・削除手順(Linux)

記事内に商品プロモーションを含む場合があります

こんにちは、やすです。

今回は、PostgreSQLでテーブルを作成・削除する手順を紹介します。

テーブルの作成、削除

事前確認

(1)postgresデータベースに接続
-bash-4.2$ whoami
postgres
-bash-4.2$
-bash-4.2$ psql postgres
psql (9.2.24)
"help" でヘルプを表示します.
postgres=#

(2)繋げているデータベースを確認
postgres=# select current_database();
 current_database
------------------
 postgres
(1 行)

postgres=#

(3)テーブルの一覧を確認
postgres=# \d
リレーションがありません。
postgres=#

テーブル作成

(4)テーブル作成
postgres=# CREATE TABLE CardInfo (
postgres(#   CardID nchar(6),
postgres(#   CustomerID nchar(5),
postgres(#   EmployeeID int
postgres(# );
CREATE TABLE
postgres=#

事後確認

(5)テーブルの一覧を確認
postgres=# \d
            リレーションの一覧
 スキーマ |   名前   |    型    |  所有者
----------+----------+----------+----------
 public   | cardinfo | テーブル | postgres
(1 行)

postgres=#

(6)テーブルのカラムを確認
postgres-> \d cardinfo
     テーブル "public.cardinfo"
     列     |      型      | 修飾語
------------+--------------+--------
 cardid     | character(6) |
 customerid | character(5) |
 employeeid | integer      |

postgres->