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!

syscolumns and sysobjects 1

Status
Not open for further replies.

mkey

Programmer
Joined
Oct 3, 2001
Messages
288
Location
CA
Hi All,
In oracle I could get the column name of a table by using user_tab_columns which will give me the column name and corresponding table name. How can I do this in sql server?

thanks
 
Code:
Select A.Name AS TableName, B.Name AS ColumnName
FROM SysObjects AS A JOIN 
SysColumns AS B ON A.ID = B.ID
WHERE A.XType = 'U'
will give you the table name and all the column names for all the user tables. is this anything like what you were looking for?
 
That's exactly what I wanted. Thank you so very much for your prompt response.
 
If you are running SQL 7 or SQL 2000 a better way to do this is by using the information_schema views.

The one you would use in this case is.

information_schema.columns.

Microsoft does not suggest using the sys files directly (although we all do it) since the structures may change.

They do say that the information_schema views will not change (with the possible exception of additional fields), so I have been trying to use those where possible.

 
cool! thanks for the info fluteplr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top