
PostgreSQLでテーブルのカラムの一覧を表示します。
テーブルを作成する!
authenticationというテーブルを作成します。
inventory=# create table authentication (
user_id VARCHAR ( 50 ) PRIMARY KEY,
username VARCHAR ( 50 ) UNIQUE NOT NULL,
password VARCHAR ( 50 ) NOT NULL,
email VARCHAR ( 255 ) UNIQUE NOT NULL,
created_on TIMESTAMP NOT NULL,
last_login TIMESTAMP
);
CREATE TABLE
inventory=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------------+-------+----------
public | authentication | table | postgres
(1 row)
テーブルのカラムの一覧を表示する!
作成したauthenticationテーブルのカラムの一覧を表示します。
inventory=# \d authentication
Table "public.authentication"
Column | Type | Collation | Nullable | Default
------------+-----------------------------+-----------+----------+---------
user_id | character varying(50) | | not null |
username | character varying(50) | | not null |
password | character varying(50) | | not null |
email | character varying(255) | | not null |
created_on | timestamp without time zone | | not null |
last_login | timestamp without time zone | | |
Indexes:
"authentication_pkey" PRIMARY KEY, btree (user_id)
"authentication_email_key" UNIQUE CONSTRAINT, btree (email)
"authentication_username_key" UNIQUE CONSTRAINT, btree (username)
おわりに
PostgreSQLでテーブルの作成と削除は、psqlの「\d <テーブル名>」コマンドで行います。
参考情報
関連記事
参考書籍(Amazon)
