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、查詢表的所有列及其屬性
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中查看一張表是否有主鍵,主鍵在哪個字段上
1. 利用Oracle中系統(tǒng)自帶的兩個視圖可以實現(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 主鍵名;
總結
到此這篇關于oracle中如何查詢所有用戶表的表名、主鍵名稱、索引及外鍵等的文章就介紹到這了,更多相關oracle查詢所有表名主鍵名稱索引內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Oracle 8x監(jiān)控sysdba角色用戶登陸情況
Oracle 8x監(jiān)控sysdba角色用戶登陸情況...2007-03-03Oracle中ROW_NUMBER()OVER()函數用法實例講解
Oracle中的row_number()函數用于在查詢結果中為每一行生成一個唯一的行號,下面這篇文章主要給大家介紹了關于Oracle中ROW_NUMBER()OVER()函數用法的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-04-04