If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Select table for a specific column name

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-17-06, 01:35
umasankaran umasankaran is offline
Registered User
 
Join Date: Jan 2004
Location: india
Posts: 5
Exclamation Select table for a specific column name

i would like to find out the table from all the tables in my database which is having same field name .

Eg.

i would like to find out the tables from all my tables containing field name customer_name.

please give the sql for this type of problem?
Reply With Quote
  #2 (permalink)  
Old 01-17-06, 03:26
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
depending on the SQL engine you are using you should be able to identify these using the schema tables, or system tables.
Reply With Quote
  #3 (permalink)  
Old 01-18-06, 00:32
umasankaran umasankaran is offline
Registered User
 
Join Date: Jan 2004
Location: india
Posts: 5
Post

depending upon system table i would like to search table
Reply With Quote
  #4 (permalink)  
Old 01-18-06, 16:06
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
OK, but what database do you work with? In Oracle, you could try with
Code:
SQL> select table_name from all_tab_columns where column_name = 'EMPNO';

TABLE_NAME
------------------------------
EMP

SQL>
but I doubt that there's "all_tab_columns" table in SQL Server or MySQL or DB2 or ... All those databases surely have similar table, but it is impossible to suggest a correct answer until you provide more information.
Reply With Quote
  #5 (permalink)  
Old 01-19-06, 06:05
kropes2001 kropes2001 is offline
Registered User
 
Join Date: Nov 2005
Location: Honolulu HI
Posts: 118
how do i delete a duplicate post ?
__________________
.
.
http://www.GetMySiteOnline.com - Can you help me Get My Site Online ? (Yes. That is EXACTLY what we do.)

http://www.GetMySiteOnline.com/FightingSpam/
__________________________
caeli enarrant gloriam Dei !

Last edited by kropes2001; 01-19-06 at 06:10.
Reply With Quote
  #6 (permalink)  
Old 01-19-06, 06:05
kropes2001 kropes2001 is offline
Registered User
 
Join Date: Nov 2005
Location: Honolulu HI
Posts: 118
in MS SQL you can use :
Set rs = Connection.OpenSchema(20)
that will give you a listing of all of the table names in a recordset.

then you loop through them and get a list of the fields in each table

Code:
<html>
<body>

	<%
	Set rs = TheDatabase.OpenSchema(20)
	if not rs.eof then
		rs.MoveFirst
		do while Not rs.eof
		strTableType=rs.fields("TABLE_TYPE")
		if strTableType="TABLE" then
			strTableName=rs.fields("TABLE_NAME")

			SQL="SELECT TOP 1 * FROM " & strTableName
			Set rsData = TheDatabase.Execute(SQL)
	%>
			<table cellspacing=0 border=1>
				<tr nowrap><%	
					intFieldCount=rsData.fields.count-1
					for iintFieldCounter = 0 to intFieldCount
						FieldName=rsData.fields(iintFieldCounter).name 
					%>
					<td><center><font color="<%=strTableHeaderTextColor%>">&nbsp;&nbsp;<%=FieldName%>&nbsp;&nbsp;</td>	<%
					next%>
				</tr>
			</tabel><br>
			<%=strTableName%>&nbsp;&nbsp;&nbsp;(<%=strTableType%>)

	<%
			end if
		rs.MoveNext
		loop
	end if
	rs.Close

	%>

</body>
</html>
of course you can change this a round a bit to do what you need...
__________________
.
.
http://www.GetMySiteOnline.com - Can you help me Get My Site Online ? (Yes. That is EXACTLY what we do.)

http://www.GetMySiteOnline.com/FightingSpam/
__________________________
caeli enarrant gloriam Dei !
Reply With Quote
  #7 (permalink)  
Old 01-20-06, 08:48
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
In DB2 this would be
Code:
SELECT rtrim(tbcreator) || '.' || tbname
FROM   sysibm.syscolumns
WHERE  name = 'EMPNO'
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/

Last edited by Peter.Vanroose; 01-20-06 at 08:54.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On