新聞中心
在Linux環(huán)境下,oracle數(shù)據(jù)庫中查詢表主鍵、外鍵及索引的命令是什么?
要通過查詢ORACLE的數(shù)據(jù)字典才能知道。
為澄海等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及澄海網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、澄海網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
1、查主鍵名稱:
select * from user_constraints
where table_name = 'ART'
and constraint_type ='P';
查主鍵對應(yīng)的列:
select * from user_cons_columns
where table_name = 'ART'
and constraint_name = 'PK_ART';
2、查索引名稱:
select * from user_indexes
where table_name = 'ART';
查索引對應(yīng)的列:
select * from user_ind_columns
where table_name = 'ART'
and index_name = 'INDX_BA';
Oracle查看表索引、主鍵、外鍵、約束
查看表索引、主鍵、外鍵、約束
(包括索引名,類型,構(gòu)成列)
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'; ----指定用戶
(包括名稱,構(gòu)成列)
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'; -----指定用戶名
(包括表名稱,構(gòu)成列)
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怎么查看外鍵在哪個表
有時候刪除某張表記錄的時候,會報錯外鍵約束不能刪除。
如果不了解表之間的關(guān)系,可以通過以下語句查詢到外鍵是建在哪張表上的:
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) - 未找到父項關(guān)鍵字
select * from dba_constraints where constraint_name='FK66EC57AF5158B9FB' and constraint_type = 'R';
例如:
執(zhí)行delete from tablename時報錯:
ORA-02292: integrity constraint (CCSYS.FK_T_BME_TASKRUNRESULT_TASKID) violated - child record found
可以通過執(zhí)行
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中查詢所有用戶表的表名、主鍵名稱、索引、外鍵等
查詢出所有的用戶表。
查所有用戶的表在all_tables
主鍵名稱、外鍵在all_constraints
索引在all_indexes
但主鍵也會成為索引,所以主鍵也會在all_indexes里面。
具體需要的字段可以DESC下這幾個view,dba登陸的話可以把all換成dba。
查詢用戶表的索引(非聚集索引):
select * from user_indexes
where uniqueness = 'NONUNIQUE '
查詢用戶表的主鍵(聚集索引):
select * from user_indexes
where uniqueness = 'UNIQUE '
1、查找表的所有索引(包括索引名,類型,構(gòu)成列):
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、查找表的主鍵(包括名稱,構(gòu)成列):
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、查找表的唯一性約束(包括名稱,構(gòu)成列):
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、查找表的外鍵(包括名稱,引用表的表名和對應(yīng)的鍵名,下面是分成多步查詢):
select * from user_constraints c where c.constraint_type = 'R' and c.table_name = 要查詢的表
查詢外鍵約束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵名稱
查詢引用表的鍵的列名:
在oracle中查詢表之間外鍵的執(zhí)行語句怎么寫?
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)是全球大型數(shù)據(jù)庫軟件公司,總部位于美國加州紅木城的紅木岸。在2008年,甲骨文股份有限公司是繼Microsoft及IBM后,全球收入第三多的軟件公司。
Oracle數(shù)據(jù)庫產(chǎn)品為財富排行榜上的前1000家公司所采用,許多大型網(wǎng)站也選用了Oracle系統(tǒng)。甲骨文股份有限公司于1989年正式進入中國,在北京、上海、廣州和成都均設(shè)立了分支機構(gòu)。
oracle 查詢外鍵的名稱
需要通過查詢系統(tǒng)表user_constraints來獲得外鍵名稱。
例如,查詢跟emp表相關(guān)的外鍵,可用如下語句:
select?*?from?user_constraints?where?table_name='EMP';
查詢結(jié)果:
其中紅框部分即為外鍵名稱。
本文標(biāo)題:Oracle外鍵怎么查,oracle查詢所有外鍵
新聞來源:http://fisionsoft.com.cn/article/dsipegs.html