postgreSQL常用命令

2021-09-13 18:25:32 字數 1004 閱讀 4649

1.新增字段

alter table "表名" add column "欄位名" 屬性:varchar(255);

alter table "***" add column "test" varchar(255) not null;

2.刪除字段

alter table "表名" drop column "欄位名";
3.查詢x表中所有索引

select * from pg_indexes where tablename='表名';
4.建立索引

create index "索引名" on "表名" using btree(索引方法) ("欄位名");
5.刪除索引

drop index "索引名";
6.建立唯一約束

alter table "表名" add constraint "約束名" unique ("約束字段");
7.刪除約束條件(刪除唯一鍵, 外來鍵, 檢查鍵, )

alter table "表名" drop constraint "約束鍵名";
8.新增外來鍵

alter table "表名" add constraint "外鍵名" foreign key ("外來鍵字段") 

references "關聯表" ("關聯字段") on delete set null on update no action;

9.新增sql檢查

alter table "表名" add constraint "檢查約束名" check ((條件));

alter table "res_user" add constraint "yueshu" check ((id < 10000000));

postgresql常用命令

最近一直在學習postgresql,下面是自己整理的postgresql的常用命令 連線資料庫,預設的使用者和資料庫是postgres psql u user d dbname 切換資料庫,相當於mysql的use dbname c dbname 列舉資料庫,相當於mysql的show databa...

postgresql常用命令

最近一直在學習postgresql,下面是自己整理的postgresql的常用命令 連線資料庫,預設的使用者和資料庫是postgres psql u user d dbname 切換資料庫,相當於mysql的use dbname c dbname 列舉資料庫,相當於mysql的show databa...

postgresql常用命令

最近一直在學習postgresql,下面是自己整理的postgresql的常用命令 連線資料庫,預設的使用者和資料庫是postgres psql u user d dbname 切換資料庫,相當於mysql的use dbname c dbname 列舉資料庫,相當於mysql的show databa...