SQL数据字典

显示所有表的表名、字段名、字段长度、字段说明的SQL语句

SELECT Sysobjects.name AS TABLE_NAME, syscolumns.Id, syscolumns.name AS COLUMN_NAME,
        systypes.name AS DATA_TYPE, syscolumns.length as CHARACTER_MAXIMUM_LENGTH, 
        sys.extended_properties.[value] AS COLUMN_DESCRIPTION,  
        syscomments.text as COLUMN_DEFAULT,syscolumns.isnullable as IS_NULLABLE 
   FROM syscolumns
INNER JOIN systypes  
          ON syscolumns.xtype = systypes.xtype 
LEFT JOIN sysobjects ON syscolumns.id = sysobjects.id 
LEFT OUTER JOIN sys.extended_properties 
               ON ( sys.extended_properties.minor_id = syscolumns.colid
              AND sys.extended_properties.major_id = syscolumns.id) 
LEFT OUTER JOIN syscomments ON syscolumns.cdefault = syscomments.id 
WHERE syscolumns.id IN   (SELECT id FROM SYSOBJECTS WHERE xtype = 'U') 
   AND (systypes.name <> 'sysname')   ORDER BY Sysobjects.Name,syscolumns.colid;

 

 

posted @ 2012-12-06 16:02  寂静之秋  阅读(825)  评论(0编辑  收藏  举报
哈尔滨八零网