查找列是否具有唯一约束
在一个假设的场景中,我是没有表创建特权的用户.我想知道表中的列是否具有 UNIQUE CONSTRAINT .是否可以在字典中查找它?我该怎么办?
In a hypothetical scenario, I am an user with no table creation privileges. I want to know if a column in a table has UNIQUE CONSTRAINT. Is it possible to look it up in the DICTIONARY? How would I go about it?
此处给出的两个答案都缺少一种在列上实施唯一性的方法:通过创建唯一索引(未在上定义唯一约束)列).查看这两个链接(一个,
Both answers given here miss one way to enforce uniqueness on a column: by creating a unique index (without defining a unique constraint on the column). See these two links (one, two) if you are not familiar with this option.
此检查应另外执行,以进行唯一性约束检查:
This check should be performed additionally to the unique constraint check:
select count(*) from
USER_IND_COLUMNS cols
where cols.table_name='YOUR_TABLE_NAME'
and cols.COLUMN_NAME='YOUR_COLUMN';
要检查唯一约束,请使用已经提供的方法:
To check for a unique constraint use the already provided method:
select count(*) cnt
from user_constraints uc
where uc.table_name='YOUR_TABLE_NAME'
and uc.constraint_type='U';
或者,您也可以在ALL_CONSTRAINTS
和ALL_IND_COLUMNS
视图中查看.
Alternatively you can also look in the ALL_CONSTRAINTS
and ALL_IND_COLUMNS
views.