获得当前数据库对象依赖关系的实用算法
作者:13301 发布时间:2009-01-08 13:28:00
标签:
本文主要介绍了一个获得当前数据库对象依赖关系的实用算法,具体示例请大家参考下文:
create function udf_GenLevelPath()
returns @v_Result table (LevelPath int,OName sysname)
/****************************************************************/
/* 功能描述:按照依赖关系,列出数据库对象 */
/* 输入参数:无 */
/* 输出参数:按照依赖关系排列的数据库对象表,无依赖在前 */
/* 编写: anna*/
/* 时间:2007-12-12 */
/****************************************************************/
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
0
投稿
猜你喜欢
- 最近做拍卖小程序,里面有一个需求是监控拍卖时间,需要对时间进行动态的倒计时显示从构思开始,做这个倒计时也花了我4个小时多,也遇到了很多问题,
- 今天学到了如何使用Python的smtplib库发送邮件,中间也是遇到了各种各样的错误和困难,还好都一一的解决了。下面来谈一谈我的这段经历。
- 1.数据的容量:1-3年内会大概多少条数据,每条数据大概多少字节; 2.数据项:是否有大字段,那些字段的值是否经常被更新; 3.数据查询SQ
- 本文实例讲述了python实现的登录与提交表单数据功能。分享给大家供大家参考,具体如下:# !/usr/bin/env python# -*
- 有些页面并不能直接用requests获取到内容,会动态执行一些js代码生成内容。这个文章主要是对付那些特殊页面的,比如必须要进行js调用才能
- 用户不想输入账号密码,一键登录 <label for="" @click="LoginDL&q
- 安装pyqt5wind@wind-ThinkPad-X250:~/Downloads/PyQt5_gpl-5.12.2$ python3 -
- 变量类型ECMAScript变量可能包含两种不同类型的数据值:基本类型和引用类型。基本类型基本类型指的是简单的数据段,5种基本数据类型:un
- 环境准备 python3.52 pycharm5.05 Pillow 自制的验证码工具包/utils/check_code 验证码的作用防恶
- 环境:主服务器:centos 5.2 mysql 5.1.35 源码 IP:192.168.1.22从服务器:centos 5.2 mysq
- 简单方法实现网页自动适应任何分辨率任何窗口大小(只适用于IE)<!DOCTYPE html PUBLIC "-//W3C//
- Django 中自带了 sitemap框架,用来生成 xml 文件Sitemap(站点地图)是通知搜索引擎页面的地址,页面的重要性,帮助站点
- 以前做音乐项目的时候,最让我们头痛的就是满足用户的问题。在音乐的领域,不要试图去满足所有用户这个定律得到了最充分的验证。究其原因,无非是音乐
- 需求:看到朋友圈有人发词云照片,感觉自己也可以玩一玩,于是乎借助wordcloud实现功能。环境:MacOS 10.12 +Python 2
- domainname.asp<form method="POST"> &nb
- 和网友们讨论了数组取交集的方法,下面是两个实现arr1=["1","5","6"
- Python 用了好长一段时间了,起初是基于对爬虫的兴趣而接触到的。随着不断的深入,慢慢的转了其它语言,毕竟工作机会真的太少了。很多技能长时
- 本文实例讲述了Python实现的基数排序算法。分享给大家供大家参考,具体如下:基数排序(radix sort)属于“分配式排序”(distr
- 本文实例讲述了PHP实现微信公众号支付功能。分享给大家供大家参考,具体如下: 直言无讳,我就是一个初涉微信
- 闲的无聊。。。网上一堆,正好练手(主要是新手)# coding=utf-8 import requests from bs4 import