mydb-# \d List of relations Schema | Name | Type | Owner --------+------------+-------+---------- public | company | table | postgres public | department | table | postgres (2 rows)
输入\d table查看具体表的信息
1 2 3 4 5 6 7 8 9 10 11
mydb-# \d company Table "public.company" Column | Type | Collation | Nullable | Default ---------+---------------+-----------+----------+--------- id | integer | | not null | name | text | | not null | age | integer | | not null | address | character(50) | | | salary | real | | | Indexes: "company_pkey" PRIMARY KEY, btree (id)
删除表
使用DROP TABLE table_name;命令。
Schema
创建schema
1 2
mydb=# create schema myschema; CREATE SCHEMA
在schema中创建表 mydb=# ```bash create table mychema.company ( id int not null, name varchar(20) not null, age int not null, address char(25), salary decimal(18,2), primary key (id) ); CREATE TABLE
通过\d看不到schema.table
1 2 3 4 5 6 7
mydb=# \d List of relations Schema | Name | Type | Owner --------+------------+-------+---------- public | company | table | postgres public | department | table | postgres (2 rows)
可以通过select操作和\d schema.table查看,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
mydb=# select * from myschema.company; id | name | age | address | salary ----+------+-----+---------+-------- (0 rows)
mydb=# \d myschema.company Table "myschema.company" Column | Type | Collation | Nullable | Default ---------+-----------------------+-----------+----------+--------- id | integer | | not null | name | character varying(20) | | not null | age | integer | | not null | address | character(25) | | | salary | numeric(18,2) | | | Indexes: "company_pkey" PRIMARY KEY, btree (id)