views:

47

answers:

3

Is there a relatively easy way to find an instance of a character, say a "|" or a "~" or a "&", in a database?

It could be in any field...in any table.

There are around 400 to 500 tables in the database in total.

+1  A: 

the easiest way is to bulk export all the data for all of the tables and then search/grep for the string in question.

http://msdn.microsoft.com/en-us/library/ms187042.aspx

KM
Probably easier than dynamic SQL...
gbn
Thanks, we're trying this now...turns out there are more tables/data than I thought so it's going to take awhile.
Jason
+1  A: 

You could export the database to one big SQL script using the SQL Management Console. Once you have the text file you can use notepad/grep/etc. to find the characters you're looking for.

Good for code... but why not search syscomments?
gbn
+1  A: 

This code will identify each table and varchar column in your database. It could be used to generate a select statement for each table and column to search for rows where that column contains the characters you're looking for.

select o.id, o.name, c.name, t.name, t.*
from sysobjects o
join syscolumns c on c.id = o.id
join systypes t on t.xtype = c.xtype
where o.xtype = 'U'
      and t.status = 0
      and t.name like '%varchar'
order by o.name, c.name

Depending on the size and indexing of your tables this may or may not be a good idea.

Crappy Coding Guy
This was my first thought as well. It looks like it is going to be very tedious to look through all the results...I suppose I could run a query that sends some sort of notification including the table, etc when it finds a match. Thanks for the help.
Jason
Yes - rather than generating SELECT statements, generate INSERT statements into a common table and include the table and column names.
Crappy Coding Guy