Thursday, November 11, 2010

How to find SQL Server object

If you need to find, if so and so object (stored procedure, table, function) exists in the database, following queries could be of help to you :

SELECT * FROM SYSOBJECTS WHERE NAME LIKE '%ObjectName%'

If you know the type of object, even better :
SELECT * FROM SYSOBJECTS WHERE XTYPE = 'U' AND NAME LIKE '%ObjectName%'
-- 'U' denotes a User Table

If you need to find out if the object exists in any of the databases on the system :

EXEC sp_MSforeachdb 'SELECT * FROM ?..SYSOBJECTS WHERE XTYPE= ''U'' AND NAME LIKE '%ObjectName%'

No comments:

Post a Comment