Column info in SQL Server 2005
-
Hi, I need to retrieve the column info only from a table that i created in the DB. Though I know it can be done using sys.objects/sys.columns, i do not know how to form the query. please help.
-
Hi, I need to retrieve the column info only from a table that i created in the DB. Though I know it can be done using sys.objects/sys.columns, i do not know how to form the query. please help.
Retrieving column names of a table There are basically 3 approaches to this problem: 1.Use the
sp_help
procedure to get extended information about a database object. By database object, we mean a table, view etc. 2.You can use the following select statement to retrieve a table’s columns:SELECT TOP 0 * FROM table_name
3.The third approach, which I personally prefer, is using the schema object of SQL Server. For example, to retrieve the column names of Authors table, you can use the followingSELECT
statement:SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME 'authors'
Which results in the following result set:column_name ---------------------------- au_id au_lname au_fname phone address city state zip contract (9 row(s) affected)
Tirtha Do not go where the path may lead, go instead where there is no path and leave a trail. Author: Ralph Waldo Emerson (1803-82), American writer, philosopher, poet, essayist