以前用那个SQL语句来生成那个SQLServer库的数据字典,在SQL2000下用的挺好的,最近装上了那个SQL2008来研究,
突然发现不能在2008下用了,查了查资料,发现2008下有一些改动
贴上来留个记号
SQLServer2008/2005 生成数据字典语句
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/f0cd6c7f9e7ae96feae062cb48f670f0.gif)
以前的SQL2000下的语句
就改动了个sysproperties
![点击图片可在新窗口打开](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
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,
标识=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
主键=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 = 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,''),
字段说明=isnull(g.[value],'')
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<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sysproperties g on a.id=g.id and a.colid=g.smallid
left join sysproperties f on d.id=f.id and f.smallid=0
--where d.name='要查询的表' --如果只查询指定表,加上此条件
order by a.id,a.colorder
SQL语句如下,在查询分析器中执行即可生成整个数据库的全部表的数据字典:
本文相关代码如下:
本文相关代码如下:
SELECT 表名 = CASE WHEN a.colorder = 1 THEN d .name ELSE '' END, 字段名 = a.name,
类型 = b.name, 长度 = CAST(COLUMNPROPERTY(a.id, a.name, 'PRECISION')
AS VARCHAR(4000)) + CASE WHEN COLUMNPROPERTY(a.id, a.name, 'Scale') IS NULL
THEN '' ELSE ',' + CAST(COLUMNPROPERTY(a.id, a.name, 'Scale')
AS VARCHAR(100)) END,
空 = CASE WHEN a.isnullable = 1 THEN '是' ELSE '否' END, 默认值 = isnull(e.text, ''),
字段说明 = isnull(CAST(g.[value] AS Varchar(4000)), '')
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 <> 'dtproperties' LEFT
JOIN
syscomments e ON a.cdefault = e.id LEFT JOIN
sysproperties g ON a.id = g.id AND a.colid = g.smallid
ORDER BY a.id, a.colorder
多处转载,就不附上网址了