欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【获得当前数据库对象依赖关系的实用算法】,下面是详细的分享!
获得当前数据库对象依赖关系的实用算法
create function udf_GenLevelPath()
returns @v_Result table (LevelPath int,OName sysname)
as
begin
declare @vt_ObjDepPath table (LevelPath int,OName sysname null)
declare @vt_Temp1 table (OName sysname null)
declare @vt_Temp2 table (OName sysname null)
--依赖的级别,值越小依赖性越强
declare @vi_LevelPath int
set @vi_LevelPath = 1
--得到所有对象,不包括系统对象
insert into @vt_ObjDepPath(LevelPath,OName)
select @vi_LevelPath,o.name
from sysobjects o
where xtype not in ('S','X')
--得到依赖对象的名称
insert into @vt_Temp1(OName)
select distinct object_name(sysdepends.depid)
from sysdepends,@vt_ObjDepPath p
where sysdepends.id <> sysdepends.depid
and p.OName = object_name(sysdepends.id)
--循环处理:由对象而得到其依赖对象
while (select count(*) from @vt_Temp1) > 0
begin
set @vi_LevelPath = @vi_LevelPath + 1
update @vt_ObjDepPath
set LevelPath = @vi_LevelPath
where OName in (select OName from @vt_Temp1)
and LevelPath = @vi_LevelPath - 1
delete from @vt_Temp2
insert into @vt_Temp2
select * from @vt_Temp1
delete from @vt_Temp1
insert into @vt_Temp1(OName)
select distinct object_name(sysdepends.depid)
from sysdepends,@vt_Temp2 t2
where t2.OName = object_name(sysdepends.id)
and sysdepends.id <> sysdepends.depid
end
select @vi_LevelPath = max(LevelPath) from @vt_ObjDepPath
--修改没有依赖对象的对象级别为最大
update @vt_ObjDepPath
set LevelPath = @vi_LevelPath + 1
where OName not in (select distinct
object_name(sysdepends.id) from sysdepends)
and LevelPath = 1
insert into @v_Result
select * from @vt_ObjDepPath order by LevelPath desc
return
end
go
--调用方法
select * from dbo.udf_GenLevelPath()
go
以上所分享的是关于获得当前数据库对象依赖关系的实用算法,下面是编辑为你推荐的有价值的用户互动:
相关问题:如何查看 SQL 依赖关系 (SQL Server Management St...
答:在对象资源管理器中,连接到数据库引擎实例,然后展开该实例。展开“数据库”,展开对象所在的数据库,再展开对象所属的文件夹。例如,如果对象是一个存储过程,请展开“可编程性”,再展开“存储过程”。右键单击该对象,然后单击“查看依赖关系”。若... >>详细
相关问题:如何判断一个数据库表是否满足一个给定的函数依赖...
答:经过对部分考生的调查以及对近年真题的总结分析,笔试部分经常考查的是算法复杂度、数据结构的概念、栈、二叉树的遍历、二分法查找,读者应对此部分进行重点学习。 1.算法的概念、算法时间复杂度及空间复杂度的概念 2.数据结构的定义、数据逻... >>详细
相关问题:关系数据库 面向对象数据库异同
答:数据库管理系统发展到了今天,可以说已经到了极致,多年以来,人们一直在追求数据库系统与程序设计语言的完美结合。以关系数据库为例,SQL语言是一种非过程化的面向集合的语言,它虽然用起来非常简单,但由于是解释实现,效率不如人意。因此许多... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
