Monday, 15 July 2013

Searching for a string in all tables of database in SQL Server 2000 -



Searching for a string in all tables of database in SQL Server 2000 -

there many answers in many places question, such as:

search string in tables, rows , columns of db

however using sql server 2000 , need same thing: search tables in database specific string.

declare @searchstring varchar(32); set @searchstring = 'something'; create table #results(o nvarchar(512), c sysname, value nvarchar(4000)); declare @sql nvarchar(4000), @o nvarchar(512), @c sysname; declare c cursor local fast_forward select quotename(u.name) + '.' + quotename(o.name), quotename(c.name) sysobjects o inner bring together syscolumns c on o.id = c.id inner bring together sysusers u on o.uid = u.uid c.xtype in (35, 99, 167, 175, 231, 239) , o.xtype = 'u'; open c; fetch c @o, @c; while @@fetch_status = 0 begin set @sql = n'insert #results(o,c,value) select @o, @c, convert(nvarchar(4000), ' + @c + ') ' + @o + ' ' + @c + ' ''%' + @searchstring + '%'';'; exec sp_executesql @sql, n'@o nvarchar(512), @c sysname', @o, @c; fetch c @o, @c; end close c; deallocate c; select o, c, value #results; drop table #results;

sql-server sql-server-2000

No comments:

Post a Comment