Solved

Table created in Stored Procedure

Posted on 2014-10-24
7
6 Views
Last Modified: 2016-06-15
I have a table that is created by Stored procedure. Is there a way quick to use query to identify which procedure generating this table ?

Tks
0
Comment
Question by:AXISHK
7 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 40402453
If you know the table name please try following select in SSMS against that specific dabatase (not master):

select * from sys.syscomments where text like '%PutYourTableNameHere%';
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 40402633
You mean from outside that proc?  No, not unless you store that info somewhere.

If you mean can the proc "identity itself" as it's running, then yes, using @@PROCID.
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40402796
If your question is 'What SP whose name I don't know creates table x?', then the below code will return all SP's with the value x in it.  If the set is too big, or if you feel lucky, change x to CREATE TABLE x
SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
   AND definition LIKE '%x%'

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 69

Expert Comment

by:ScottPletcher
ID: 40403048
That doesn't actually tell you that proc did create that table, just that it potentially could have created it.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40403054
Granted.  Didn't have anything else to offer up, as table properties / sys.tables / sys.objects does not speak to it.
0
 

Author Comment

by:AXISHK
ID: 40405660
Tks. It works fine only when I use a database that contains the store procedure. Can it be further enhancement to search through all database ? Tks


SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
   AND definition LIKE '%x%'
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now