weinerk
asked on
"grep" through SQL DB?
How can I "grep" through SQL DB?
Meaning looking for a string of data in one of the tables in one of the fields but not sure which ones.
One way to export the whole DB as a bunch of inserts and use grep.
But I am looking for a SQL code sort of like sp_grep,
but which will search through the actual data in DB.
Meaning looking for a string of data in one of the tables in one of the fields but not sure which ones.
One way to export the whole DB as a bunch of inserts and use grep.
But I am looking for a SQL code sort of like sp_grep,
but which will search through the actual data in DB.
hmm not sure whether there is a facility like that.. but if you wish to create the queries automagically for this kind of a job then you can do this., are you trying to reverse engineer from an thrid party application DB :)
select 'select * from ' + sysobjects.name + ' where ' + syscolumns.name +' like ''%stringtosearch%'' '
from syscolumns , sysobjects, systypes
where sysobjects.xtype='U' and sysobjects.id = syscolumns.id and systypes.xtype=syscolumns. xtype
and systypes.name <> 'sysname'
and systypes.name in ('varchar','char','nvarcha r','nchar' ,'text','t ext')
order by sysobjects.name,syscolumns .colid
select 'select * from ' + sysobjects.name + ' where ' + syscolumns.name +' like ''%stringtosearch%'' '
from syscolumns , sysobjects, systypes
where sysobjects.xtype='U' and sysobjects.id = syscolumns.id and systypes.xtype=syscolumns.
and systypes.name <> 'sysname'
and systypes.name in ('varchar','char','nvarcha
order by sysobjects.name,syscolumns
IMHO, you should explain the reason why you try to "grep" the whole database. Usually, only a certain set of tables and columns should be searched for, anything else will be - if used/usable by users - a good performance and security killer.
You might create a stored procedure that explicitely searches this given set of tables and columns and returns the data to the user/application.
You might create a stored procedure that explicitely searches this given set of tables and columns and returns the data to the user/application.
ASKER
So far user-dsine
is the closest to what I wanted.
Idealy would be nice if this is all wraped up together
in a storproc or a piece of code
to loop through all the statements and add descriptive output
so it will be obvious which tables/fields the results were found.
is the closest to what I wanted.
Idealy would be nice if this is all wraped up together
in a storproc or a piece of code
to loop through all the statements and add descriptive output
so it will be obvious which tables/fields the results were found.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT mycol
FROM mytable
WHERE mycol like '%grep%'