Click here to Skip to main content
15,911,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello,

How to identify table names in below query.

SQL
select c.cid,c1.cname from tablename1 c inner join tablename2 c1 on c.cid=c1.cid



tablename1 :-- first table

tablename2:-- second table, these two are table names, but how to identify.


thanks
Posted
Updated 27-Dec-11 2:16am
v3
Comments
thatraja 27-Dec-11 8:13am    
Not clear
#realJSOP 27-Dec-11 8:18am    
Do you mean parsing the string *in* a sql server stored proc?
Varun Sareen 27-Dec-11 8:21am    
Question is not clear dear
K N R 27-Dec-11 8:23am    
Hi John,

i will clarify you what i exactly need in the above query am using two tables.
By seeing that query i can find out which table i am using and how many tables are am using. Now what i want is am storing a queries which are using in sql server (ssms). I want to know in that query how many tables are there and which tables those are but my problem is i can't see that query.
So with out seeing that query how could i find out the tables of used in that query.
Tejas Vaishnav 27-Dec-11 8:45am    
please clear you question its not properly asked...

in this query you can get table name like this.. it C then Table 1 or C1 then table2

1 solution

"So with out seeing that query how could i find out the tables of used in that query"

You can't. A query could return results from any number of tables with multiple joins and subqueries or it could return results from a view which is comprised of data from multiple table or views.

If you had access to SQL Profiler on the database server you could follow the trace.
 
Share this answer
 
v2
Comments
K N R 27-Dec-11 8:34am    
Hi Mark,

Yes, your are right. That's not a possible to find tables if i used views in my query but i want to find tables from query which doesn't used views in the queries. I am taking a queries which doesn't have a views.
[no name] 27-Dec-11 9:01am    
It doesn't matter whether the query uses views or not. If you don't have the SQL there is no way to know exactly which tables where used. The results only return the columns requested.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900