首页 > 开发 > 综合 > 正文

获取MS SQL库数据字典的经典SQL语句

2024-07-21 02:11:57
字体:
来源:转载
供稿:网友

select sysobjects.name as [table], sysproperties.[value] as 表说明,
      syscolumns.name as field, properties.[value] as 字段说明, systypes.name as type,
      syscolumns.length, isnull(columnproperty(syscolumns.id, syscolumns.name,
      'scale'), 0) as 小数位数, syscolumns.isnullable as isnull,
      case when syscomments.text is null
      then '' else syscomments.text end as [default],
      case when columnproperty(syscolumns.id, syscolumns.name, 'isidentity')
      = 1 then '√' else '' end as 标识, case when exists
          (select 1
         from sysobjects
         where xtype = 'pk' and name in
                   (select name
                  from sysindexes
                  where indid in
                            (select indid
                           from sysindexkeys
                           where id = syscolumns.id and colid = syscolumns.colid)))
      then '√' else '' end as 主键
from syscolumns inner join
      sysobjects on sysobjects.id = syscolumns.id inner join
      systypes on syscolumns.xtype = systypes.xtype left outer join
      sysproperties properties on syscolumns.id = properties.id and
      syscolumns.colid = properties.smallid left outer join
      sysproperties on sysobjects.id = sysproperties.id and
      sysproperties.smallid = 0 left outer join
      syscomments on syscolumns.cdefault = syscomments.id
where (sysobjects.xtype = 'u')


  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表