Recentemente precisei de todas as tabelas em uma procedure no SQL Server. Buscando em alguns arquivos guardados encontrei alguns scripts que mostram exatamente isso.
Abaixo vou colocar-los, fiz alguns testes eles não funcionam caso a tabela esteja em um outro banco de dados ou outro servidor, ou seja, funciona para as tabelas no banco de dados local que está consultando.
;WITH stored_procedures AS (SELECT o.name AS NomeDaProcedure, oo.name AS NomeDaTabela, ROW_NUMBER() OVER (PARTITION BY o.name, oo.name ORDER BY o.name, oo.name) AS row FROM sysdepends d INNER JOIN sysobjects o ON o.id = d.id INNER JOIN sysobjects oo ON oo.id = d.depid WHERE o.xtype = 'P') SELECT NomeDaProcedure, NomeDaTabela FROM stored_procedures WHERE row = 1 /*Caso queira filtrar por nome da procedure*/ --AND NomeDaProcedure = '' ORDER BY NomeDaProcedure, NomeDaTabela
SELECT DISTINCT so.name FROM syscomments sc INNER JOIN sysobjects so ON sc.id = so.id WHERE sc.TEXT LIKE '%NomeDaTabela%' -- Segunda opção: SELECT DISTINCT o.name, o.xtype FROM syscomments c INNER JOIN sysobjects o ON c.id = o.id WHERE c.TEXT LIKE '%NomeDaTabela%'
Apreciem
Casinos online offer free spins to draw new customers. These bonuses are usually very profitable,…
In recent times, online casino sites have actually obtained enormous appeal among gamers, providing a…
Bitcoin, the most preferred cryptocurrency worldwide, has reinvented lots of industries, including the on baixar…
Online slots have turned into one of one of the most preferred forms of home…
Port video games have actually long been a popular type of entertainment, providing exhilarating gameplay…