PostgreSQL 删除check约束的实现
时间:2021-06-14 09:46:06|栏目:PostgreSQL|点击: 次
删除check约束:
1.\d table_name 查找约束名称
\d dm_alarms_fct_20170613 "dm_alarms_fct_20170613_dm_transct_date_key_check"
2.alter table .. drop constraint ..
ALTER TABLE "dm_alarms_fct_20170613" Drop constraint "dm_alarms_fct_20170613_dm_transct_date_key_check";
补充:PostgreSQL查询约束和创建删除约束
查询约束constraint
SELECT tc.constraint_name, tc.table_name, kcu.column_name, ccu.table_name AS foreign_table_name, ccu.column_name AS foreign_column_name, tc.is_deferrable,tc.initially_deferred FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'UNIQUE' AND tc.table_name = 'table_name';
constraint_type有四种:
UNIQUE、PRIMARY KEY、CHECK、FOREIGN KEY, 通过修改上边sql语句的table_name和constraint_type来进行相应的查询。
添加约束
ALTER TABLE table_name ADD CONSTRAINT uk_users_name1 UNIQUE (NAME);
删除约束
alter table table_name drop constraint if EXISTS uk_users_name1;
上一篇:PostgreSQL TIMESTAMP类型 时间戳操作
栏 目:PostgreSQL
下一篇:在windows下手动初始化PostgreSQL数据库教程
本文地址:http://www.codeinn.net/misctech/141720.html