---
title: "oracle"
author: "xiaoyaocai"
date: "2011-05-05T17:41:59Z"
tags: ["C", "C#", "C++", "Oracle"]
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2011-05-05T17:41:59Z"
id: 1030495
url: "https://xiaoyaocai.iteye.com/blog/1030495"
---

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 = 要查询的表