欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

oracle中如何查詢所有用戶表的表名、主鍵名稱、索引及外鍵等

 更新時(shí)間:2023年12月19日 09:50:29   作者:小小哭包  
在與Oracle進(jìn)行數(shù)據(jù)庫操作時(shí),往往會需要查詢數(shù)據(jù)庫表列表,以便對其進(jìn)行操作,這篇文章主要給大家介紹了關(guān)于oracle中如何查詢所有用戶表的表名、主鍵名稱、索引及外鍵等的相關(guān)資料,需要的朋友可以參考下

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 = 外鍵名稱 

查詢引用表的鍵的列名: 

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

附:oracle中查看一張表是否有主鍵,主鍵在哪個(gè)字段上

1. 利用Oracle中系統(tǒng)自帶的兩個(gè)視圖可以實(shí)現(xiàn)查看表中主鍵信息,

語句如下:

select a.constraint_name,  a.column_name 
from user_cons_columns a, user_constraints b 
where a.constraint_name = b.constraint_name 
and b.constraint_type = 'P' and a.table_name = '大寫的表名'

查看表的主鍵約束名稱,以及主鍵約束的字段名稱。如果沒有,則返回空

2. 順便給出創(chuàng)建主鍵和刪除主鍵的sql

向表中添加主鍵

alter table 表名 add constraint 主鍵名 primary key(列名);

刪除表中已有的主鍵約束

???????alter table 表名 drop constraint 主鍵名;

總結(jié) 

到此這篇關(guān)于oracle中如何查詢所有用戶表的表名、主鍵名稱、索引及外鍵等的文章就介紹到這了,更多相關(guān)oracle查詢所有表名主鍵名稱索引內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論