Determining Field Data Type

Determining Field Data Type

Is there a non-platform-specific SQL way of determining what data type a given field is?

That information is specific to each database. Every product stores its meta data differently. For example, SQL Server stores meta data in the system tables, which are all named according to its own standards.

This query returns all the table columns and data types in a SQL Server database:

SELECT AS TableName, AS ColName, AS 'Data Type'FROM syscolumns sc INNER JOIN sysobjects so ON = INNER JOIN systypes st ON sc.xtype = st.xtypeWHERE (so.xtype = 'U')

If you want a generic procedure, you’ll have to use different queries and put in logic to check the current database.


Share the Post: