Skip to content

Instantly share code, notes, and snippets.

@renatocfrancisco
Last active January 13, 2023 14:57
Show Gist options
  • Save renatocfrancisco/3ea81215907fdb9a15a1ad6ce0ebfe8e to your computer and use it in GitHub Desktop.
Save renatocfrancisco/3ea81215907fdb9a15a1ad6ce0ebfe8e to your computer and use it in GitHub Desktop.
SQL para encontrar tabelas com certo campo.
DECLARE @Busca VARCHAR(8000)
SET @Busca = 'campo'
SELECT
Colunas.COLUMN_NAME,
Tabelas.TABLE_NAME
FROM
INFORMATION_SCHEMA.TABLES Tabelas
INNER JOIN INFORMATION_SCHEMA.COLUMNS Colunas
ON Tabelas.TABLE_NAME = Colunas.TABLE_NAME
WHERE
(Tabelas.TABLE_TYPE='BASE TABLE') AND
(
(Tabelas.TABLE_NAME LIKE '%' + @Busca + '%') OR
(Colunas.COLUMN_NAME LIKE '%' + @Busca + '%')
)
ORDER BY
Tabelas.TABLE_NAME ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment