如何获得当前数据库对象依赖关系_MySQL

php中文网
发布: 2016-06-01 14:00:37
原创
1758人浏览过

具体示例的源代码,请大家参考下文:

ChatBA
ChatBA

AI幻灯片生成工具

ChatBA 74
查看详情 ChatBA
<P>create function udf_GenLevelPath()   <BR>returns @v_Result table (LevelPath int,OName sysname)   <BR>/****************************************************************/   <BR>/* 功能描述:按照依赖关系,列出<U><STRONG><FONT color=#333333 size=3>数据库</FONT></STRONG></U><U><STRONG><FONT color=#333333 size=3>对象</FONT></STRONG></U> */   <BR>/* 输入参数:无 */   <BR>/* 输出参数:按照依赖关系排列的数据库对象表,无依赖在前 */   <BR>/* 编写: anna*/   <BR>/* 时间:2007-12-12 */   <BR>/****************************************************************/   <BR>as   <BR>begin   <BR>declare @vt_ObjDepPath table (LevelPath int,OName sysname null)   <BR>declare @vt_Temp1 table (OName sysname null)   <BR>declare @vt_Temp2 table (OName sysname null)   <BR>--依赖的级别,值越小依赖性越强   <BR>declare @vi_LevelPath int       <BR>set @vi_LevelPath = 1   <BR>--得到所有对象,不包括系统对象           <BR>insert into @vt_ObjDepPath(LevelPath,OName)   <BR>select @vi_LevelPath,o.name   <BR>from sysobjects o   <BR>where xtype not in ('S','X')   <BR><BR>--得到依赖对象的名称   <BR>insert into @vt_Temp1(OName)   <BR>select distinct object_name(sysdepends.depid)     <BR>from sysdepends,@vt_ObjDepPath p   <BR>where sysdepends.id <> sysdepends.depid   <BR>and p.OName = object_name(sysdepends.id)   <BR><BR>--循环处理:由对象而得到其依赖对象   <BR>while (select count(*) from @vt_Temp1) > 0   <BR>begin   <BR>set @vi_LevelPath = @vi_LevelPath + 1   <BR><BR>update @vt_ObjDepPath   <BR>set LevelPath = @vi_LevelPath   <BR>where OName in (select OName from @vt_Temp1)   <BR>and LevelPath = @vi_LevelPath - 1   <BR><BR>delete from @vt_Temp2   <BR><BR>insert into @vt_Temp2   <BR>select * from @vt_Temp1   <BR><BR>delete from @vt_Temp1   <BR><BR>insert into @vt_Temp1(OName)   <BR>select distinct object_name(sysdepends.depid)     <BR>from sysdepends,@vt_Temp2 t2   <BR>where t2.OName = object_name(sysdepends.id)   <BR>and sysdepends.id <> sysdepends.depid  <BR><BR>end       </P><P>select @vi_LevelPath = max(LevelPath) from @vt_ObjDepPath   <BR><BR>--修改没有依赖对象的对象级别为最大   <BR>update @vt_ObjDepPath   <BR>set LevelPath = @vi_LevelPath + 1   <BR>where OName not in (select distinct   <BR>object_name(sysdepends.id) from sysdepends)   <BR>and LevelPath = 1   <BR><BR>insert into @v_Result   <BR>select * from @vt_ObjDepPath order by LevelPath desc   <BR>return   <BR>end   <BR>go   <BR><BR>--调用方法   <BR>select * from dbo.udf_GenLevelPath()   <BR>go</P>
登录后复制
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号