Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Tables Collection in SQL

Status
Not open for further replies.

jfrost10

Programmer
Joined
Jun 3, 2001
Messages
2,004
Location
CA
Hey guys,

I need to be able to cycle through the Tables collection within a stored procedure, and if a column is found in the table I need some code executed.

I'm trying to find anything on the MS help or msdn, but so far no luck. Can anyone help me out?

Thanks,
Jack

 

You can use the Information_schema views in SQL 7 and 2000.

Select
Table_Schema As Table_Owner,
Table_Name
From Information_Schema.Tables

Select
Table_Name,
Column_Name
From Information_Schema.Columns

You can also query the system tables.

Find user table names.

Select Name From sysobjects where type='u'

Find column names in table 'sales'.

Select Name As ColName
From syscolumns
Where Object_name(id)='sales' Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top