获得当前数据库中对象的依赖关系的算法
2004-09-03 22:08
387 查看
create function udf_GenLevelPath_Table()
?returns @v_Result table (LevelPath int,OName sysname,type varchar(8))
/****************************************************************/
/*?功能描述:按照依赖关系,列出数据库对象????????????????????????????????????????????? ?*/
/*?输入参数:无?????????????????????????????????????????????????????????????????????????????????????????????????? */
/*?输出参数:按照依赖关系排列的数据库对象表,无依赖的在前?????????????? */
/*?编??????? 写:我????????????????????????????????????????????????????????????????????????????????????????????????? ?*/
/*?时间:2003-9-9??????????????????????????????????????????????????????????????????????????????????????????????? */
/****************************************************************/
as
begin
?declare @vt_ObjDepPath table (LevelPath int,OName sysname null, type Varchar(8))
?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,type)
??select @vi_LevelPath,o.name,o.type
???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
?returns @v_Result table (LevelPath int,OName sysname,type varchar(8))
/****************************************************************/
/*?功能描述:按照依赖关系,列出数据库对象????????????????????????????????????????????? ?*/
/*?输入参数:无?????????????????????????????????????????????????????????????????????????????????????????????????? */
/*?输出参数:按照依赖关系排列的数据库对象表,无依赖的在前?????????????? */
/*?编??????? 写:我????????????????????????????????????????????????????????????????????????????????????????????????? ?*/
/*?时间:2003-9-9??????????????????????????????????????????????????????????????????????????????????????????????? */
/****************************************************************/
as
begin
?declare @vt_ObjDepPath table (LevelPath int,OName sysname null, type Varchar(8))
?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,type)
??select @vi_LevelPath,o.name,o.type
???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
相关文章推荐
- 获得当前数据库对象依赖关系的实用算法
- 查找当前用户的所有数据库对象的依赖关系
- 查看数据库对象间的依赖关系
- PostgreSQL每日一贴-数据库对象依赖关系
- 发现数据库对象的依赖关系
- 查询数据库对象依赖关系
- 更新数据库对象依赖关系
- 13. 查看数据库对象间的依赖关系
- 细粒度依赖(一)通过数据字典找到数据库对象之间的引用关系
- 13. 查看数据库对象间的依赖关系
- 发现数据库对象的依赖关系
- 此数据库没有有效所有者,因此无法安装数据库关系图支持对象
- Spring之对象依赖关系
- 面向对象基础知识三:依赖关系
- 面向对象设计对象之间关系---依赖、关联、聚合和组合
- 数据库对象关系查询
- SQL文的写法, 不使用Use, 访问当前数据库以外的数据库的对象
- 获得oracle存储过程以及函数的依赖对象
- Observer 在对象之间定义一个一对多的依赖关系,从而当一个对象状态发生改变时,所有依赖于这个对象的对象都能够得到通知,并对上述改变做出反应.
- SQL2000滴系统存储过程--sp_changeobjectowner(更改当前数据库中对象的所有者)