oracle中查詢表的信息,包括表名,字段名,字段類型,主鍵,外鍵唯一性約束信息


來源於網上整理

 

 

 

總結了一下oracle中查詢表的信息,包括表名,字段名,字段類型,主鍵,外鍵唯一性約束信息,索引信息查詢SQL如下,希望對大家有所幫助:

1、查詢出所有的用戶表
select * from user_tables 可以查詢出所有的用戶表
select owner,table_name from all_tables; 查詢所有表,包括其他用戶表

通過表名過濾需要將字母作如下處理

select * from user_tables where table_name = upper('表名')

因為無論你建立表的時候表名名字是大寫還是小寫的,create語句執行通過之后,對應的user_tables表中的table_name字段都會自動變為大寫字母,所以必須通過內置函數upper將字符串轉化為大寫字母進行查詢,否則,即使建表語句執行通過之后,通過上面的查詢語句仍然查詢不到對應的記錄。
2、查詢出用戶所有表的索引
select * from user_indexes
3、查詢用戶表的索引(非聚集索引):
select * from user_indexes where uniqueness='NONUNIQUE'
4、查詢用戶表的主鍵(聚集索引):
select * from user_indexes where uniqueness='UNIQUE'
5、查詢表的索引
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and

t.table_name='NODE'
6、查詢表的主鍵
select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and

au.constraint_type = 'P' AND cu.table_name = 'NODE'
7、查找表的唯一性約束(包括名稱,構成列):
select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name=au.constraint_name and

cu.table_name='NODE'
8、查找表的外鍵
select * from user_constraints c where c.constraint_type = 'R' and c.table_name='STAFFPOSITION'
查詢外鍵約束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵名稱
查詢引用表的鍵的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵引用表的鍵名
9、查詢表的所有列及其屬性
方法一:

select * from user_tab_columns where table_name=upper('表名');

方法二:

select cname,coltype,width from col where tname=upper('表名');;

10.查詢一個用戶中存在的過程和函數
select object_name,created,status from user_objects 
where lower(object_type) in ('procedure','function');

11.查詢其它角色表的權限
select * from role_tab_privs ;

 

12

 Oracle復制表結構及數據
1. 復制表結構及其數據: 
create table table_name_new as select * from table_name_old 
2. 只復制表結構: 
create table table_name_new as select * from table_name_old where 1=2; 
或者:
create table table_name_new like table_name_old
3. 只復制表數據:如果兩個表結構一樣:
insert into table_name_new select * from table_name_old 
兩個表結構不一樣:
insert into table_name_new(column1,column2...) select column1,column2... from table_name_old


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM