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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find out names and data types of table fields

Status
Not open for further replies.

pigsie

Programmer
Dec 19, 2000
307
GB
Hi I'm aware that there are some system tables that hold the name and datatypes of table fields how can i retreive these in a query. Also is there a way (again using a query or stored proc) to find out other info about the field such as range,defaults, constraints etc)?


Thanks
 
Below query returns the field name, Corresponding Datatype, Deafult Value, Nullable Flag, Maximum Legth:

SELECT Column_name, Data_type, Column_Default,Is_Nullable,
Character_Maximum_Length FROM INFORMATION_SCHEMA.Columns
WHERE TABLE_NAME = '<Table Name>'

// in the above query INFORMATION_SCHEMA.Columns is a view which contains all the information.

There are many other views from where you can find the other information needed. If you have online help search for INFORMATION_SCHEMA and you will get all the relevant information.
 
You can also run the stored procedure sp_columns. This stored procedure will return all of the columns in the specified table with their data types and field lengths.

Code:
exec sp_columns @table_name = '[YourTableName]'

Jamey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top