Solved

Table created in Stored Procedure

Posted on 2014-10-24
7
10 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 40

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:Scott Pletcher
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 69

Expert Comment

by:Scott Pletcher
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

737 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