域名預(yù)訂/競(jìng)價(jià),好“米”不錯(cuò)過(guò)
這篇文章主要介紹了PostgreSQL 刪除check約束的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧。
刪除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";
補(bǔ)充: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, 通過(guò)修改上邊sql語(yǔ)句的table_name和constraint_type來(lái)進(jìn)行相應(yīng)的查詢。
添加約束
1ALTER TABLE table_name ADD CONSTRAINT uk_users_name1 UNIQUE (NAME);
刪除約束
1alter table table_name drop constraint if EXISTS uk_users_name1;
文章來(lái)源:腳本之家
來(lái)源地址:https://www.jb51.net/article/205217.htm
申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!