---
title: "oracle收藏（查询索引、约束等）"
author: "wjeye"
date: "2011-12-28T14:50:29Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2011-12-28T14:50:29Z"
id: 1328601
url: "https://wjeye.iteye.com/blog/1328601"
---

1、查找表的所有索引（包括索引名，类型，构成列）：

select t.\*,i.index\_type from user\_ind\_columns t,user\_indexes i where t.index\_name = i.index\_name and t.table\_name = i.table\_name and t.table\_name = 要查询的表

2、查找表的主键（包括名称，构成列）：

select cu.* from user\_cons\_columns cu, user\_constraints au where cu.constraint\_name = au.constraint\_name and au.constraint\_type = 'P' and au.table\_name = 要查询的表

3、查找表的唯一性约束（包括名称，构成列）：

select column\_name from user\_cons\_columns cu, user\_constraints au where cu.constraint\_name = au.constraint\_name and au.constraint\_type = 'U' and au.table\_name = 要查询的表

4、查找表的外键（包括名称，引用表的表名和对应的键名，下面是分成多步查询）：

select * from user\_constraints c where c.constraint\_type = 'R' and c.table\_name = 要查询的表

查询外键约束的列名：

select * from user\_cons\_columns cl where cl.constraint\_name = 外键名称

查询引用表的键的列名：

select * from user\_cons\_columns cl where cl.constraint\_name = 外键引用表的键名

5、查询表的所有列及其属性

select t.\*,c.COMMENTS from user\_tab\_columns t,user\_col\_comments c where t.table\_name = c.table\_name and t.column\_name = c.column\_name and t.table\_name = 要查询的表

6、根据索引名称查找 目标表  
select * from user\_indexes where index\_name ='索引名称';

 

-------oracle查询用户所有表的语句介绍。

select * from all\_tab\_comments  
\-- 查询所有用户的表,视图等

select * from user\_tab\_comments    
\-- 查询本用户的表,视图等

select * from all\_col\_comments  
 

--查询所有用户的表的列名和注释.

select * from user\_col\_comments  
\-- 查询本用户的表的列名和注释

select * from all\_tab\_columns  
\--查询所有用户的表的列名等信息(详细但是没有备注).

select * from user\_tab\_columns  
\--查询本用户的表的列名等信息(详细但是没有备注).

--一般使用1:  
select t.table\_name,t.comments from user\_tab\_comments t

--一般使用2:  
[]()[select r1, r2, r3, r5  
from (select a.table\_name r1, a.column\_name r2, a.comments r3  
from user\_col\_comments a),  
(select t.table\_name r4, t.comments r5 from user\_tab\_comments t)  
where r4 = r1]()