Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

sql server 2008 - encontre quais tabelas contêm texto específico


para encontrar as colunas da tabela, use:
SELECT table_name=sysobjects.name,
         column_name=syscolumns.name
    FROM sysobjects 
    JOIN syscolumns ON sysobjects.id = syscolumns.id
    JOIN systypes ON syscolumns.xtype=systypes.xtype
   WHERE sysobjects.xtype='U'
ORDER BY sysobjects.name,syscolumns.colid

se você quiser que os dados nas tabelas usem sql dinâmico, você pode fazer algo nestas linhas:
Declare @Sql varChar(100)
Declare @Temp Table (Ind INT, TableName nvarchar(100))

Insert Into @Temp
Select Row_Number() Over(Order BY [Name]), [Name]
FROM
(
    Select [Name]
    from sys.tables
) AS D

Declare @index int
Set @index = 1
while @index < (Select Count(*) From @Temp)
begin
SET @SQL = ' Select * From ' + (Select TableName From @Temp Where Ind = @index)


exec (@SQL)
Set @index = @index + 1
End