查找列是否具有唯一约束 [英] Find if a column has unique constraint

查看:112
本文介绍了查找列是否具有唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个假设的场景中,我是没有表创建特权的用户.我想知道表中的列是否具有 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_CONSTRAINTSALL_IND_COLUMNS视图中查看.

Alternatively you can also look in the ALL_CONSTRAINTS and ALL_IND_COLUMNS views.

这篇关于查找列是否具有唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆