[dba-SQLServer] List of fields in a table

jwcolby jwcolby at colbyconsulting.com
Mon Dec 14 07:34:59 CST 2009


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



More information about the dba-SQLServer mailing list