Friday, May 1, 2009

Sys on SQL

Not sharing query, but some tips that might be useful when looking for a needle in a haystack.
Am using Microsoft SQL Server 2000, but won't differ too much on later versions, I guess.

Find tables with the specified name

-----------------------------------
select name from sysobjects where name like '%table_name%' and type = 'u'



Find stored procedures with the specified name
----------------------------------------------
select name from sysobjects where name like '%sp_name%' and type = 'p'



Find the name of the tables which contain specified column
----------------------------------------------------------
select TableName = a.name, ColumnName = b.name from sysobjects a, syscolumns b
where a.id = b.id and b.name = 'column_name'



Find stored procedures which contain certain key / text
-------------------------------------------------------
select name from sysobjects where id in ( select id from syscomments where text like '%text_in_sp%')

This is also useful when you would like to search for stored procedures which uses a certain table.
e.g. If you would like to know the stored procedures which use the table named table_name,
select name from sysobjects where id in ( select id from syscomments where text like '%table_name%')
Share:

1 comment:

You may be intersted in

Related Posts

Updating Table Containing Xml Column via LinkedServer

If you are trying to update a table containing XML column via Linked Server in SQL Server, and you are not able to, you are not alone. There...

About Me

My photo
Is an ordinary man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing.

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts

Blogroll

Followers

Leave a Message