Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the SQL command to return the field names of a table?

Say I have a table called myTable. What is the SQL command to return all of the field names of this table? If the answer is database specific then I need SQL Server right now but would be interested in seeing the solution for other database systems as well.

like image 383
WalkingRandomly Avatar asked Sep 19 '08 08:09

WalkingRandomly


People also ask

What are field names in SQL?

Field names are the names you give to the columns in a table. The names should indicate what data is contained in each column. For example, when you create a feature class in ArcCatalog, the table is prepopulated with an Object ID field and a shape field.

Which command is used to get details of field of a table?

The MySQL's DESCRIBE or DESC both are equivalent. The DESC is the short form of DESCRIBE command and used to dipslay the information about a table like column names and constraints on column name.


1 Answers

MySQL 3 and 4 (and 5):

desc tablename 

which is an alias for

show fields from tablename 

SQL Server (from 2000) and MySQL 5:

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

Completing the answer: like people below have said, in SQL Server you can also use the stored procedure sp_help

exec sp_help 'tablename' 
like image 60
Vinko Vrsalovic Avatar answered Oct 05 '22 19:10

Vinko Vrsalovic