devxlogo

Determining Field Data Type

Determining Field Data Type

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

Answer:
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 so.name AS TableName, sc.name AS ColName,st.name AS 'Data Type'FROM syscolumns sc INNER JOIN sysobjects so ON sc.id = so.id 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.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist