资讯

精准传达 • 有效沟通

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

oracle怎么查询外键,oracle查询外键约束的父表和子表

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

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

创新互联是一家专业提供龙海企业网站建设,专注与成都网站设计、成都网站制作、外贸网站建设成都h5网站建设、小程序制作等业务。10年已为龙海众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。

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

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中查询表之间外键的执行语句怎么写?

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)是全球大型数据库软件公司,总部位于美国加州红木城的红木岸。在2008年,甲骨文股份有限公司是继Microsoft及IBM后,全球收入第三多的软件公司。

Oracle数据库产品为财富排行榜上的前1000家公司所采用,许多大型网站也选用了Oracle系统。甲骨文股份有限公司于1989年正式进入中国,在北京、上海、广州和成都均设立了分支机构。

如何在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 查询外键的名称

需要通过查询系统表user_constraints来获得外键名称。

例如,查询跟emp表相关的外键,可用如下语句:

select * from user_constraints where table_name='EMP';

查询结果:

其中红框部分即为外键名称。

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怎么查询外键,oracle查询外键约束的父表和子表
文章分享:http://cdkjz.cn/article/phgpeh.html
多年建站经验

多一份参考,总有益处

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

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

大客户专线   成都:13518219792   座机:028-86922220