具体示例的源代码,请大家参考下文:
<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>登录后复制 |
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号