IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置: 首頁(yè)數(shù)據(jù)庫(kù)MSSQL → 獲得當(dāng)前數(shù)據(jù)庫(kù)對(duì)象依賴關(guān)系的實(shí)用算法

獲得當(dāng)前數(shù)據(jù)庫(kù)對(duì)象依賴關(guān)系的實(shí)用算法

時(shí)間:2015-06-28 00:00:00 來(lái)源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評(píng)論(0)

本文主要介紹了一個(gè)獲得當(dāng)前數(shù)據(jù)庫(kù)對(duì)象依賴關(guān)系的實(shí)用算法,具體示例請(qǐng)大家參考下文:

以下為引用的內(nèi)容:
create?? function?? udf_GenLevelPath()??
? returns?? @v_Result?? table?? (LevelPath?? int,OName?? sysname)??
? /****************************************************************/??
? /* 功能描述:按照依賴關(guān)系,列出數(shù)據(jù)庫(kù)對(duì)象 */??
? /* 輸入?yún)?shù):無(wú) */??
? /* 輸出參數(shù):按照依賴關(guān)系排列的數(shù)據(jù)庫(kù)對(duì)象表,無(wú)依賴在前 */??
? /* 編寫(xiě): anna*/??
? /* 時(shí)間: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)??
? --依賴的級(jí)別,值越小依賴性越強(qiáng)??
? declare?? @vi_LevelPath?? int??
???
? set?? @vi_LevelPath?? =?? 1??
? --得到所有對(duì)象,不包括系統(tǒng)對(duì)象????
? insert?? into?? @vt_ObjDepPath(LevelPath,OName)??
? select?? @vi_LevelPath,o.name??
? from?? sysobjects?? o??
? where?? xtype?? not?? in?? ('S','X')??
???
? --得到依賴對(duì)象的名稱??
? 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)??
???
? --循環(huán)處理:由對(duì)象而得到其依賴對(duì)象??
? 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??
???
? --修改沒(méi)有依賴對(duì)象的對(duì)象級(jí)別為最大??
? 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??
???
? --調(diào)用方法??
? select?? *?? from?? dbo.udf_GenLevelPath()??
? go

關(guān)鍵詞標(biāo)簽:數(shù)據(jù)庫(kù)

相關(guān)閱讀

文章評(píng)論
發(fā)表評(píng)論

熱門(mén)文章 淺談JSP JDBC來(lái)連接SQL Server 2005的方法 淺談JSP JDBC來(lái)連接SQL Server 2005的方法 SqlServer2005對(duì)現(xiàn)有數(shù)據(jù)進(jìn)行分區(qū)具體步驟 SqlServer2005對(duì)現(xiàn)有數(shù)據(jù)進(jìn)行分區(qū)具體步驟 sql server系統(tǒng)表?yè)p壞的解決方法 sql server系統(tǒng)表?yè)p壞的解決方法 MS-SQL2005服務(wù)器登錄名、角色、數(shù)據(jù)庫(kù)用戶、角色、架構(gòu)的關(guān)系 MS-SQL2005服務(wù)器登錄名、角色、數(shù)據(jù)庫(kù)用戶、角色、架構(gòu)的關(guān)系

相關(guān)下載

    人氣排行 配置和注冊(cè)O(shè)DBC數(shù)據(jù)源-odbc數(shù)據(jù)源配置教程 如何遠(yuǎn)程備份(還原)SQL2000數(shù)據(jù)庫(kù) SQL2000數(shù)據(jù)庫(kù)遠(yuǎn)程導(dǎo)入(導(dǎo)出)數(shù)據(jù) SQL2000和SQL2005數(shù)據(jù)庫(kù)服務(wù)端口查看或修改 修改Sql Server唯一約束教程 SQL Server 2005降級(jí)到2000的正確操作步驟 sql server系統(tǒng)表?yè)p壞的解決方法 淺談JSP JDBC來(lái)連接SQL Server 2005的方法