2017-02-04 77 views
0

我已經在postgresql中創建了一個表,並向其中一列添加了唯一約束。我如何確保這個約束被添加?如何檢查表的列上的其他唯一約束?如何查看是否將唯一約束添加到列

我想在psql的終端界面上做這個。

回答

0

使用\d <table_name>,如:

create table test (id int primary key, str text); 
alter table test add constraint test_str_unique unique (str); 
\d test 

    Table "public.test" 
Column | Type | Modifiers 
--------+---------+----------- 
id  | integer | not null 
str | text | 
Indexes: 
    "test_pkey" PRIMARY KEY, btree (id) 
    "test_str_unique" UNIQUE CONSTRAINT, btree (str) 
0

使用pgAdmin的,你可以看到表

對於測試表中添加了所有的限制,你可以在對象瀏覽器中看到此如下

Tables (2) 
    test 
    Columns 
    Constraints 
    Indexes 
    Rules 
    Triggers 

展開約束,你不能看到所有的約束添加到表測試

+0

終端界面怎麼樣? – orezvani