zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    HashMap 统计一个字符串中每个单词出现的次数
    iOS .a静态库的制作及使用
    iOS framework静态库中使用xib和图片资源详解
    iOS 工程套子工程,主工程和framework工程或.a library静态库工程联调
    iOS 最新framework和.a静态库制作及使用全解(含工程套工程,多工程联调)
    iOS9新特性 3DTouch 开发教程全解(含源码)
    iOS GCD NSOperation NSThread等多线程各种举例详解
    Mac Beyond Compare 永久试用
    cocoapods 常见问题
    iOS 常用工具库LFKit功能介绍
  • 原文地址:https://www.cnblogs.com/llhhll/p/8315589.html
Copyright © 2011-2022 走看看