系统开发过中,2分钟之内搞定数据字典表文档的更新
来源:互联网 发布:送餐软件哪个软件挣钱 编辑:程序博客网 时间:2024/05/21 14:03
系统开发过中,数据字典表的更新
你们是否发现,
在系统开发过程中,你的数据库在不停的改变,最初发给每个开发人员的数据表定义,
已经变得面目全非了,如果你这个这个项目开发的负责人,下面的人老师说,怎么数据表又变了
怎么也不通知我们呢,有时候工作繁忙,也不一定能够通知到所有的开发人员。
为此,我特地作了一个自动化的工具,每当数据表又大的变动时,你不需要再次去修改原始数据字典文档了
你只要按照我的步骤来做,保证这一切在2分钟之内,帮你搞定数据字典文档的更新。
注意本方法,只针对MS SQL Server 2000。很遗憾,这一切,还没有做到完全自动化,谁有这个兴趣,完善它,我相信到时候,这一切会在1分钟之内搞定。
1. 在你的系统数据库中,创建以下存储过程
该存储过程是获取数据字典信息
create Procedure GetAllTableInfo As
begin
DECLARE @au_id varchar(11), @strName varchar(50), @Tid int,@strOwner varchar(50)
--获取所有的用户表信息
DECLARE All_Tables CURSOR
FOR select convert(varchar,Name),ID from sysobjects where xtypE='U' order by Name
Create Table #ColInfo
(
TName varchar(50), --表名称
ColName varchar(50), --列名称
REMARK sql_variant, --注释
Type varchar(50), --数据类型
DefaultValue varchar(255), --缺省值
IsAllowNull varchar(10), --是否允许为空
IsPrimaryKey char(2) --是否为主键,用*标记
)
--主键信息
Create Table #PkInfo
(
TABLE_QUALIFIER varchar(50),
TABLE_OWNER varchar(50),
TABLE_NAME varchar(50),
COLUMN_NAME varchar(50),
KEY_SEQ int,
PK_NAME varchar(50)
)
set @strOwner=user_name()
OPEN All_Tables
FETCH NEXT FROM All_Tables into @strName,@Tid
while @@FETCH_STATUS = 0
begin
--插入表及其注释信息
Insert Into #ColInfo
SELECT @StrName,'',isnull(Value,''),'','','',''
FROM (select @strName TName) A left join
::fn_listextendedproperty('MS_Description', N'USER', N'dbo', N'Table', @strName, NULL, NULL) --表的注释信息
ON 1=1
--插入列信息
insert into #ColInfo
select @strName,C.name CName,convert(varchar,R.value)+(case c.status when 0x80 then char(13)+char(10)+'自动增长列' else '' end),
(case when (C.xtype>=34 and C.xtype<=58) or C.xtype in (61,98,99,104,127,189) then T.name when c.xtype in (59,60,106,108,122) then T.name+'('+convert(varchar,C.xprec)+','+convert(varchar,C.xscale)+')' else T.name+'('+convert(varchar,C.length)+')' end),
isnull(Def.text,''),
case isnullable when 1 then '是' else '否' end,
''
from (systypes T
inner join
(
syscolumns C
left join
SysComments Def
on C.cdefault=Def.id and 1=Def.colid
)
on T.xtype=C.xtype and T.xusertype=C.xusertype
)
left join
::fn_listextendedproperty('MS_Description', N'USER', N'dbo', N'Table', @strName, N'Column', NULL) R --列的注释信息
on convert(varchar,R.objname)=convert(varchar,C.Name)
where C.id=object_id(@strName)
insert into #PkInfo EXEC [dbo].[sp_pkeys] @strName,@strOwner, DEFAULT
fetch next from All_Tables into @strName,@Tid
end
--更新主键信息
update #ColInfo
set IsPrimaryKey='是'
from #PkInfo
where #PkInfo.TABLE_NAME=#ColInfo.TName and #PkInfo.COLUMN_NAME=#ColInfo.ColName
Close All_Tables
DEALLOCATE All_Tables
select '%%%%' ObjName,'' REMARK,'' Col1,'' Col2,'' Col3,'' Col4,TName,0 flag
from #ColInfo
where ColName=''
union
select '表名:'+TName,REMARK,'','','','',TName,1 flag
from #ColInfo
where ColName=''
union
select '列名','注释','数据类型','缺省值','是否允许空','主键',TName,2
from #ColInfo
where ColName=''
union
select ColName,REMARK,Type,DefaultValue,IsAllowNull,
IsPrimaryKey,TName,3
from #ColInfo
where ColName<>''
order by 7,8,3
drop table #PkInfo
drop table #ColInfo
end
2. MS SQL Sever 提供的查询分析器中,
Exec GetAllTableInfo
3. 将查询结果信息,复制到MS Excel Sheet中
4. 在MS Excel Sheet中,删除掉最后两列
5. 全选Sheet信息,复制到MS Word中,执行下面 Word宏命令
Sub Macro1()
'
' Macro1 Macro
' 宏在 2004-3-12 由 徐侠君 录制
'
A:
Selection.Find.ClearFormatting
With Selection.Find
.Text = "%%%%"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
If Selection.Find.Execute Then
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Cells.Merge
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.SelectCell
Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
Selection.Cells.Merge
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.MoveDown Unit:=wdLine, Count:=2
GoTo A
Else
MsgBox "修改各是成功"
End If
End Sub
1. 如果还发现那些地方不符合你的要求,请自己完善
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>- 系统开发过中,2分钟之内搞定数据字典表文档的更新
- 系统开发过中,2分钟之内搞定数据字典表文档的更新
- 两分钟搞定SSH+ExtJS框架下字典表的前后台构建
- 十分钟搞定pandas(官方学习文档的译文)
- Oracle数据字典的使用(更新中)
- 寻找更新过的数据
- 开发日记(8) 为什么我的HttpUtils过一分钟才会有数据再刷新?
- oracle巨大表的数据删除的方法,20分钟搞定
- MIS系统中数据字典的两种解决方案
- 一分钟之内搞定自制16537升级,最新的自制升级方法,有网络就行,绝对好用!iqk
- Toad导出数据字典,把数据库所有的表结构导出到htm中。(写文档很有用。)
- Qt软件开发文档11---更新数据
- Android Studio开过中常用的插件,大大提高开发效率!(持续更新中)
- ORACLE主要的系统表和数据字典视图
- ORACLE主要的系统表和数据字典视图
- 5分钟搞定云应用开发
- 全网最简单的C# json数据解析 无敌菜鸟教程 十分钟搞定json数据解析
- Redis数据操作——(2)一个文档搞定
- 微软的远程处理框架.NET Remoting(转天极网)之二
- 用Cygwin模拟DB2的Unix/Linux开发环境(2)
- 从 .NET 程序集提供图像(二)
- C#中如何对当前窗体进行打印预览
- Visual Basic .NET中的异常处理简介(下)
- 系统开发过中,2分钟之内搞定数据字典表文档的更新
- 用户界面设计风格说明(转)
- PowerBuilder8.0动态连接SQL Server技巧
- PB10中Microsoft OLE DB数据库连接配置
- [c#]:如何在C#中读写INI文件(一)
- PB中读取地磅称量数据
- Henry手记— WinForm Datagrid结构剖析(一)
- 一番话--原型模式
- PB通用类库和业务类库的设计思想(二)