PostgreSQL > テーブルの操作
更新日
2014-05-06
広告
テーブルの操作は、データベースにログインしてから行います。
test_tableという名前のテーブルを作成する例を以下に示します。データ型は他にもたくさんあります。
testdb=# CREATE TABLE test_table ( testdb(# id1 int, # 4バイト整数 testdb(# id2 bigint, # 8バイト整数 testdb(# value1 real, # 4バイト小数 testdb(# value2 double precision, # 8バイト小数 testdb(# str1 char, # 固定長文字列 testdb(# str2 varchar, # 可変長文字列 testdb(# str3 text, # 可変長文字列 testdb(# date1 date, # 年月日 testdb(# ts1 timestamp # 年月日と時刻 testdb(# ); CREATE TABLEテーブルの削除は、drop table で行います。
testdb=# drop table test_table ; DROP TABLE作成済みのテーブルを一覧表示するには、'\d' を実行します。
testdb=# \d List of relations Schema | Name | Type | Owner --------+------------+-------+---------- public | test_table | table | postgres (1 row)特定のスキーマのテーブルを一覧表示するには、'\dt'を実行します。 以下の例では、’abc' というスキーのテーブルを表示します。
postgres=# \dt abc. List of relations Schema | Name | Type | Owner --------+--------------------------+-------+--------- abc | abcdefgh_info | table | postgres abc | abcdef_11111111_xxx_info | table | postgres (2 rows)
広告
お問い合わせは sweng.tips@gmail.com まで。