Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Tracking what tables appear in which queries

Posted on 2007-12-04
6
Medium Priority
?
190 Views
Last Modified: 2010-04-21
Hi

I have tables A,B,C that need to be renamed. However they are referenced in several queries and i would need some code that would list what queries these tables appear in.

Many thanks!
0
Comment
Question by:SigmundFraud
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
wittyslogan earned 800 total points
ID: 20402219
USE <database name>;

select so.name
from sysobjects as so
 inner join syscomments as sc
on so.id = sc.id
where sc.text like '%tablename%'

I assume by queries you mean stored procedures?
0
 

Author Comment

by:SigmundFraud
ID: 20402243
Thanks for the swift response.

They're in some sp's but mainly in views.
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20402250
Tables can be referenced directly by program code. It's hard to know what queries can be run by the various programs that connect to your database. However, if you only refer to Stored Procedures, Functions, and Views, then

select distinct object_name(id) from syscomments where text like '%tbl%'
order by 1
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 25

Expert Comment

by:imitchie
ID: 20402262
It's possible that procedures are created encrypted, so this technique will not work. In that case, you will need to find a decrypter (sql2000 ones are easily found) and actually decrypt each and every proc and drop/create them unencrypted before  syscomments  will reveal anything useful.
0
 
LVL 7

Expert Comment

by:wittyslogan
ID: 20402270
views should be accesible using the code as well.  we are referencing the sysobjects table
0
 

Author Closing Comment

by:SigmundFraud
ID: 31412557
Excellent solution, thanks Witty.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

972 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