這篇文章主要介紹了PostgreSQL 刪除check約束的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧。
刪除check約束:
1.\d table_name 查找約束名稱
\d dm_alarms_fct_20170613 "dm_alarms_fct_20170613_dm_transct_date_key_check"
2.alter table .. drop constraint ..
1ALTER TABLE "dm_alarms_fct_20170613" Drop constraint "dm_alarms_fct_20170613_dm_transct_date_key_check";
補充:PostgreSQL查詢約束和創(chuàng)建刪除約束
查詢約束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來進行相應(yīng)的查詢。
添加約束
1ALTER TABLE table_name ADD CONSTRAINT uk_users_name1 UNIQUE (NAME);
刪除約束
1alter table table_name drop constraint if EXISTS uk_users_name1;
文章來源:腳本之家
來源地址:https://www.jb51.net/article/205217.htm
申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點子。點擊此處,共同探討創(chuàng)業(yè)新機遇!