[dba-SQLServer] List of fields in a table

Martin Reid mwp.reid at qub.ac.uk
Mon Dec 14 08:18:18 CST 2009


John

This any use

http://msdn.microsoft.com/en-us/magazine/cc164065.aspx


martin


Martin WP Reid
Information Services
The Library at Queen's
Tel : 02890976174
Email : mwp.reid at qub.ac.uk
Sharepoint Training Portal
________________________________________
From: dba-sqlserver-bounces at databaseadvisors.com [dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby [jwcolby at colbyconsulting.com]
Sent: 14 December 2009 13:34
To: Dba-Sqlserver
Subject: [dba-SQLServer] List of fields in a table

I need to get a list of fields in a table in any database I want, in a stored procedure.  I have
found this:

select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'tblOrderData'

but that only appears to work if you execute that from a query in the target database, whereas my
stored procedure needs to take the database and table name as parameters and go get the list.

How can I get a list of fields in any table in any database, from a stored procedure saved in a
"library" database?

--
John W. Colby
www.ColbyConsulting.com
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com



More information about the dba-SQLServer mailing list