Sql Server 遍曆資料庫檔案找出使用了某個表/預存程序的所有預存程序

來源:互聯網
上載者:User

標籤:

Sql Server 遍曆資料庫檔案找出使用了某個表/預存程序的所有預存程序。

 1 CREATE Procedure SP_GetProc       2 @Object_Name Varchar(50)       3 as       4 Set nocount on       5    6 DECLARE @tmptable TABLE     7 (     8 ID int IDENTITY (1, 1),     9 [DataBase] Varchar(100),  10 Name Varchar(500),  11 Type Varchar(100),  12 Create_Date Datetime  13 )    14   15 DECLARE @SQLText TABLE    16 (    17 ID int IDENTITY (1, 1),    18 SQLText Varchar(Max)  19 )    20   21 if Charindex(‘#‘, @Object_Name) > 0  22 begin   23   Select @Object_Name = replace(@Object_Name, ‘#‘, ‘‘)  24   25   Insert Into @SQLText  26     Select ‘      27     Select ‘‘‘ + Name + ‘‘‘ [DataBase], CONVERT(VARCHAR(500), a.Name COLLATE Chinese_PRC_CI_AS) Name, a.Type, a.Create_Date      28       From ‘ + Name+ ‘.sys.all_objects a   29       Where a.Name Like ‘‘%‘ + @Object_Name + ‘%‘‘‘      30       From sys.databases where database_ID > 4      31 end  32 else begin  33   Insert Into @SQLText  34     Select ‘      35     Select ‘‘‘ + Name + ‘‘‘ [DataBase], CONVERT(VARCHAR(500), a.Name COLLATE Chinese_PRC_CI_AS) Name, a.Type, a.Create_Date      36       From ‘ + Name+ ‘.sys.all_objects a, ‘ + Name + ‘.sys.syscomments b       37       Where a.object_id = b.id and b.text Like ‘‘%‘ + @Object_Name + ‘%‘‘‘      38       From sys.databases where database_ID > 4      39 end  40   41 Declare @ID Int, @MID Int, @SQl Varchar(Max)  42 Select @ID = 1, @MID = MAX(ID) From @SQLText  43 While @ID <= @MID  44 begin   45   Select @SQl = SQLText From @SQLText Where ID = @ID  46   Insert Into @tmptable Exec (@SQl)   47   Select @ID = @ID + 1  48 end  49   50 Select * From @tmptable Order by ID  
View Code

 

Sql Server 遍曆資料庫檔案找出使用了某個表/預存程序的所有預存程序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.