Chinaunix首页 | 论坛 | 博客
  • 博客访问: 116472
  • 博文数量: 11
  • 博客积分: 1290
  • 博客等级: 中尉
  • 技术积分: 501
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-17 16:01
文章分类

全部博文(11)

文章存档

2010年(1)

2009年(2)

2008年(8)

我的朋友

分类: 数据库开发技术

2008-11-20 14:50:19

--SQL语句直接生成sql server2000数据字典
------------------------------------------------------------------------------------------------------------------------
 
SELECT  d.name  AS N'表名称',
        a.colorder  AS N'字段序号',
        a.name  AS N'字段名称',
        (CASE WHEN COLUMNPROPERTY(a.id,a.name,'IsIdentity') = 1 THEN 'YES' ELSE 'NO' END)  AS N'标识',
 (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 'YES' ELSE 'NO' END)  AS N'主键',
 b.name  AS N'类型',
 a.length  AS N'占用字节数',
 COLUMNPROPERTY(a.id,a.name,'PRECISION') AS N'长度',
 ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0) AS N'小数位数',
 (CASE WHEN a.isnullable = 1 THEN 'YES' ELSE 'NO' END) AS  N'允许空',
 ISNULL(e.text,'') AS N'默认值',
 ISNULL(g.[value],'') AS N'字段说明'
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
--------------------------------------------------------------------------------------------------------------------
SELECT 表名=case when a.colorder=1 then d.name 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
order by a.id,a.colorder
阅读(1122) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~