sqlserver 获取数据库、表和字段相关信息

--获取指定服务器上的所有数据库
SELECT Name FROM Master..SysDatabases ORDER BY Name
--获取指定数据库下所有表
SELECT Name FROM JRE..SysObjects Where XType='U' ORDER BY Name
--获取指定表的字段信息
SELECT  a.name FiledName ,
        b.name [Type] ,
        a.isnullable ,
        ISNULL(g.[value], '') AS FiledRemark
FROM    syscolumns a
        LEFT JOIN systypes b ON a.xtype = b.xusertype
        INNER JOIN sysobjects d ON a.id = d.id
                                   AND d.xtype = 'U'
                                   AND d.name IN ( 'T_Community' )
        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;

 

posted @ 2018-12-29 12:51  zhyue93  阅读(880)  评论(0编辑  收藏  举报