Looking for an Object in a SQL Database

TBSupport
TBSupport used Ask the Experts™
on
Hello:

I'm trying to look for an object in a SQL database.  I cannot tell if the object is a table, view, or stored procedure.

Is there a "select" script or something along those lines that I can run, to look for this object?

I'd rather not run anything that's going to create another object in SQL, unless doing so is easy and will not do any harm.

Thanks!

TBSupport
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Vikas GargAssociate Principal Engineer
Top Expert 2014

Commented:
Hi,

You can use this query

select * from sys.objects where name = 'Your Value'

and the column type_desc will let you know it is a  table or proc etc.
IT Engineer
Distinguished Expert 2017
Commented:
SELECT *
FROM sys.objects
WHERE name='NameOfTheObjectIWantToFind'

Open in new window

Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
why not use this free tool from Red Gate: http://www.red-gate.com/products/sql-development/sql-search/

It will not only find the object but also all the references to it.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hello:

SQL is not pulling up any records, for this object, even though it exists according to a separate stored procedure.

Could it be an alias or something that I need to look for?

Thanks!

TBSupport

Author

Commented:
Hello:

I just found out that it's a user defined function.  How do I find it and the programming behind it?

TBSupport
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
In SSMS, expand your database, than expand programmability, than Functions and you will find your UDF under one of the folder (depending on the type of UDF). You will then be able to right-click on it and select Modify to see the code behind
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
I just found out that it's a user defined function
UDFs should be returned by my query. How did you found out?

Author

Commented:
Hi Vitor:

I believe that I right-clicked on the stored proc and viewed its dependencies, to find out.

TBSupport
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Good catch.
I usually don't use SSMS options so I didn't even know that option exists. I'm an old fashion guy that likes to type SQL commands :)

Author

Commented:
Me, too!  :)

TBSupport
Scott PletcherSenior DBA
Most Valuable Expert 2018
Top Expert 2014

Commented:
You can use:
EXEC sp_helptext 'name'
to get the text for objects that have text.

You can use:
EXEC sp_help 'name'
to get info about any object in the db.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial