资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Oracle怎么查外键,oracle 查外键

Oracle查看表索引、主键、外键、约束

查看表索引、主键、外键、约束

专注于为中小企业提供成都网站建设、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业宁洱免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了千余家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

(包括索引名,类型,构成列)

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 = 'ORG_DLF' ----指定表

AND T.TABLE_OWNER= 'ODSRPT_SIT2'; ----指定用户

(包括名称,构成列)

SELECT CU.*

FROM DBA_CONS_COLUMNS CU, DBA_CONSTRAINTS AU

WHERE CU.CONSTRAINT_NAME = AU.CONSTRAINT_NAME

AND AU.CONSTRAINT_TYPE = 'P'

AND AU.TABLE_NAME = 'LOAN_APPLICATION_FEE' -----指定表名

AND CU.OWNER='ODSRPT_SIT2'; -----指定用户名

(包括表名称,构成列)

SELECT CU.COLUMN_NAME,AU.TABLE_NAME

FROM DBA_CONS_COLUMNS CU, DBA_CONSTRAINTS AU

WHERE CU.CONSTRAINT_NAME = AU.CONSTRAINT_NAME

AND AU.CONSTRAINT_TYPE = 'U'

AND AU.OWNER='RPT_UAT2' -----指定用户名

AND AU.TABLE_NAME = 表名 ; -----指定表名

Select a.Owner 外键拥有者,

a.Table_Name 外键表,

c.Column_Name 外键列,

b.Owner 主键拥有者,

b.Table_Name 主键表,

d.Column_Name 主键列,

c.Constraint_Name 外键名,

d.Constraint_Name 主键名

From User_Constraints a,

 user_Constraints b,

user_Cons_Columns c, --外键表

user_Cons_Columns d --主键表

Where a.r_Constraint_Name = b.Constraint_Name

And a.Constraint_Type = 'R'

And b.Constraint_Type = 'P'

And a.r_Owner = b.Owner

And a.Constraint_Name = c.Constraint_Name

And b.Constraint_Name = d.Constraint_Name

And a.Owner = c.Owner

And a.Table_Name = c.Table_Name

And b.Owner = d.Owner

And b.Table_Name = d.Table_Name;

如何在oracle中查询所有用户表的表名、主键名称、索引、外键等

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、查询表的所有列及其属性

oracle怎么查看外键在哪个表

有时候删除某张表记录的时候,会报错外键约束不能删除。

如果不了解表之间的关系,可以通过以下语句查询到外键是建在哪张表上的:

select * from dba_constraints where constraint_name='xxx' and constraint_type = 'R';

例如:我的程序日志中报如下错误,我要知道外键是在那个表上.

2015-09-08

18:28:18 [ main:261597003 ] - [ ERROR ] java.sql.SQLException:

ORA-02291: 违反完整约束条件 (IRP.FK66EC57AF5158B9FB) - 未找到父项关键字

select * from dba_constraints where constraint_name='FK66EC57AF5158B9FB' and constraint_type = 'R';

例如:

执行delete from tablename时报错:

ORA-02292: integrity constraint (CCSYS.FK_T_BME_TASKRUNRESULT_TASKID) violated - child record found

可以通过执行

select table_name from dba_constraints where constraint_name='FK_T_BME_TASKRUNRESULT_TASKID' and constraint_type = 'R';

查询出外键是建在T_BME_TASKRUNRESULT表上的,先把T_BME_TASKRUNRESULT表删除,就可以删除 t_bme_task表记录了。

在oracle中查询表之间外键的执行语句怎么写?

查找表的外键(包括名称,引用表的表名和对应的键名,下面是分成多步查询):

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 = 外键引用表的键名

查询表的所有列及其属性

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


本文题目:Oracle怎么查外键,oracle 查外键
标题网址:http://cdkjz.cn/article/hdjihh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220