zoukankan      html  css  js  c++  java
  • Sql语句导出数据库表结构及查询表视图储存过程名

     --一句Sql把表结构全部查询出来

    SELECT
    表名 = Case When A.colorder=1 Then D.name Else '' End,
    表说明 = Case When A.colorder=1 Then isnull(F.value,'') Else '' End,
    字段序号 = A.colorder,
    字段名 = A.name,
    字段说明 = isnull(G.[value],''),
    标识 = Case When COLUMNPROPERTY( A.id,A.name,'IsIdentity')=1 Then '√'Else '' End,
    主键 = Case When exists(SELECT 1 FROM sysobjects Where xtype='PK' and parent_obj=A.id and name in (
    SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = A.id AND colid=A.colid))) then '√' else '' end,
    类型 = B.name,
    --占用字节数 = A.Length,
    长度 = COLUMNPROPERTY(A.id,A.name,'PRECISION'),
    小数位数 = isnull(COLUMNPROPERTY(A.id,A.name,'Scale'),0),
    允许空 = Case When A.isnullable=1 Then '√'Else '' End,
    默认值 = isnull(E.Text,'')
    FROM
    syscolumns A
    Left Join
    systypes B
    On
    A.xusertype=B.xusertype
    Inner Join
    sysobjects D
    On
    A.id=D.id and D.xtype='U' and D.name<>'dtproperties'
    Left Join
    syscomments E
    on
    A.cdefault=E.id
    Left Join
    sys.extended_properties G
    on
    A.id=G.major_id and A.colid=G.minor_id
    Left Join

    sys.extended_properties F
    On
    D.id=F.major_id and F.minor_id=0
    --where d.name='OrderInfo' --如果只查询指定表,加上此条件
    Order By
    A.id,A.colorder

     --查询数据库所有表,视图,储存过程名

    select * from sysobjects
    --where xtype='U' --表名
    --WHERE xtype='V' --视图名
    --where xtype='PK' --主键
    --WHERE xtype='P' --存储过程
    --ORDER BY name ASC

  • 相关阅读:
    finereport 文档
    FineRport 工作用
    SQL 排序
    fineReport
    python | Mysql 索引优化分析
    python | 缓存穿透、缓存雪崩和缓存击穿面试题
    python | Jenkins构建Spring Boot 详细步骤
    python | MySQL全面查询的正则匹配
    python | TCP 三次握手和四次挥手图解(有限状态机)
    python | 3款工具实现快速K8S开发
  • 原文地址:https://www.cnblogs.com/Gxiaopan/p/6269423.html
Copyright © 2011-2022 走看看