zoukankan      html  css  js  c++  java
  • 如何在数据库中查询所有用户表的表名、主键名称、索引、外键

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

    ===============mssql server================

    --查询表名
    select name from sysobjects where type='U' and name like '%whir$t%'
    --
    select * from information_schema.tables
    select * from information_schema.views
    --查询所有表单详细内容
    select * from information_schema.columns
     where table_name like '%whir$t%'
     and column_name like '%_FOREIGNKEY%'

     =============mysql======================

    alter table test rename test1; --修改表名

    alter table test add  column name varchar(10); --添加表列

    alter table test drop  column name; --删除表列

    alter table test modify address char(10) --修改表列类型
    ||alter table test change address address  char(40)


    alter table test change  column address address1 varchar(30)--修改表列名

    =====================================

     附链接:http://blog.csdn.net/wentasy/article/details/7450852

    sql判断为空处理方法格式:

    --oracle
    NAL(COLUMN_NAME,1)
    --sqlserver
    ISNULL(COLUMN_NAME,1)
    --mysql
    IFNULL(COLUMN_NAME,1)

  • 相关阅读:
    Poj3126
    Poj1426
    2806 红与黑
    3100 蜗牛
    1225 八数码难题
    2549 自然数和分解
    2547 东方辉针城
    2928 你缺什么
    1629 01迷宫
    1029 遍历问题
  • 原文地址:https://www.cnblogs.com/anuoruibo/p/2454909.html
Copyright © 2011-2022 走看看