zoukankan      html  css  js  c++  java
  • SQL SERVER 以视图的方式查询表结构和视图结构

    -- =============================================
    -- Author: gengc
    -- Create date: <2012-12-29>
    -- Description: <查看表结构>
    -- =============================================

    CREATE View ViewTable
    as
    select
    obj.name as 'TableName'
    ,f.value as 'TableDesc'
    ,c.name as 'CName'
    ,isnull(etp.value,'') AS 'CDesc'
    ,t.name as '字段类型'
    ,c.Length as '占用字节'
    ,ColumnProperty(c.id,c.name,'PRECISION') as '长度'
    ,isnull(ColumnProperty(c.id,c.name,'Scale'),0) as '小数位数'
    ,case(c.isnullable) when '1' then 'Y' else '' end as '是否为空'
    ,ISNULL(cm.text,'') as '默认值'
    ,case(
    (select 1 from sysobjects where xtype='PK' and parent_obj=c.id and name in (
    select name from sysindexes where indid in(
    select indid from sysindexkeys where id = c.id and colid=c.colid)))
    ) when '1' then 'Y' else '' end as '是否主键'
    ,case(ColumnProperty(c.id,c.name,'IsIdentity')) when '1' then 'Y' else '' end as '自动增长'
    from syscolumns c
    inner join systypes t on c.xusertype = t.xusertype
    left join sys.extended_properties etp on etp.major_id = c.id and etp.minor_id = c.colid and etp.name ='MS_Description'
    left join syscomments cm on c.cdefault=cm.id
    left join sysobjects obj on c.id=obj.id
    left join sys.extended_properties f on obj.id=f.major_id and f.minor_id=0
    where obj.type='U'

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

    select [Name],[Text]

      from syscomments A

       join sysobjects B on A.id=B.id

    where [Name]='ViweName'

  • 相关阅读:
    rsync介绍和配置自动同步
    haproxy 配置httpd和httpds负载均衡
    haproxy配置及使用
    lvs之搭建NAT模式的HTTPS负载集群
    lvs配置之DR模式
    lvs配置之NAT模式
    LVS集群
    lvs四种工作模式,负载调度的介绍
    zabbix页面介绍
    zabbix自定义监控进程、日志、mysql主从
  • 原文地址:https://www.cnblogs.com/chengeng/p/4153398.html
Copyright © 2011-2022 走看看