---
title: "oracle查询约束"
author: "aniyo"
date: "2015-12-28T14:45:37Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2015-12-28T14:45:37Z"
id: 2267169
url: "https://aniyo.iteye.com/blog/2267169"
---

**查询约束类型**

select distinct constraint\_type fromdba\_constraints;

**Type Code**

**Type Description**

**Acts On Level**

**C**

Check on a table

Column

**O**

Read Only on a view

Object

**P**

Primary Key

Object

**R**

Referential AKA Foreign Key

Column

**U**

Unique Key

Column

**V**

Check Option on a view

Object

 

 

 

 

 

 

 

 

 

**查询各种约束**

user\_constraints            all\_constraints           dba\_constraints

 

**select * from user\_constraints where constraint\_type='R'**

**select * from ALL\_constraints where constraint\_type='P'**

**select * from dba\_constraintswhere constraint\_type='C'**

我们关心的视图以下列前缀命名：  
  ·USER_  ：当前用户模式下创建的对象  
  ·ALL_  ：当前用户模式下创建的对象加上当前用户能访问的其他用户创建的对象。ALL视图常常包含一个"OWNER"列，反映出能够访问的对象的所有者。在USER\_TABLES表中不能看到OWNER列是因为你就是在这个视图中所有表的所有者；在ALL\_TABLES中有一个OWNER字段。  
  ·DBA_   ：它提供了整个数据库的信息。包括数据库中所有表的名字和拥有者——包括SYS模式下的基本表  
这些前缀在限制我们想看到的、需要看到的、应当被允许看到的范围上是一个帮助。查看当前模式下创建的表，查询USER\_TABLES;

 

**修改约束**

**alter table 表名 enable/disable/dropconstraint 约束名;**