Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:14:46+00:00 2026-06-14T10:14:46+00:00

Is there a SQL statement that can return the type of a column in

  • 0

Is there a SQL statement that can return the type of a column in a table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:14:47+00:00Added an answer on June 14, 2026 at 10:14 am
    • In ISO SQL (i.e. most RDBMS today) you can use the INFORMATION_SCHEMA.COLUMNS view, which SQL Server supports.
      • This view’s DATA_TYPE column contains the T-SQL/SQL Server type names, except that it doesn’t include arguments for parameterised types, which can result in unexpected/unintentional column behaviour.
        • For example, given three columns typed as nvarchar(max), datetime2(3), and decimal(10,5) then the output will be nvarchar, datetime2, and decimal respectively.
          • This is a problem because a column typed as nvarchar (without (max) or (123)) is the same as nvarchar(1), and using decimal is the same as decimal(18,0) which cannot store non-integer values.
        • The solution is to also look at CHARACTER_OCTET_LENGTH (for binary), CHARACTER_MAXIMUM_LENGTH (for char and nchar), DATETIME_PRECISION (for datetime2 and datetimeoffset), and NUMERIC_PRECISION with NUMERIC_SCALE (for decimal and numeric) in order to reconstruct the type’s parameter values.
          • Note that float(n) can be ignored as SQL Server only supports float(24) and float(53) which are aliased by real and float respectively in the DATA_TYPE column.

    WITH q AS (
        
        SELECT
            c.TABLE_SCHEMA,
            c.TABLE_NAME,
            c.ORDINAL_POSITION,
            c.COLUMN_NAME,
            c.DATA_TYPE,
            CASE
                WHEN c.DATA_TYPE IN ( N'binary', N'varbinary'                    ) THEN ( CASE c.CHARACTER_OCTET_LENGTH   WHEN -1 THEN N'(max)' ELSE CONCAT( N'(', c.CHARACTER_OCTET_LENGTH  , N')' ) END )
                WHEN c.DATA_TYPE IN ( N'char', N'varchar', N'nchar', N'nvarchar' ) THEN ( CASE c.CHARACTER_MAXIMUM_LENGTH WHEN -1 THEN N'(max)' ELSE CONCAT( N'(', c.CHARACTER_MAXIMUM_LENGTH, N')' ) END )
                WHEN c.DATA_TYPE IN ( N'datetime2', N'datetimeoffset'            ) THEN CONCAT( N'(', c.DATETIME_PRECISION, N')' )
                WHEN c.DATA_TYPE IN ( N'decimal', N'numeric'                     ) THEN CONCAT( N'(', c.NUMERIC_PRECISION , N',', c.NUMERIC_SCALE, N')' )
            END AS DATA_TYPE_PARAMETER,
            CASE c.IS_NULLABLE
                WHEN N'NO'  THEN N' NOT NULL'
                WHEN N'YES' THEN     N' NULL'
            END AS IS_NULLABLE2
        FROM
            INFORMATION_SCHEMA.COLUMNS AS c
    )
    SELECT
        q.TABLE_SCHEMA,
        q.TABLE_NAME,
        q.ORDINAL_POSITION,
        q.COLUMN_NAME,
        CONCAT( q.DATA_TYPE, ISNULL( q.DATA_TYPE_PARAMETER, N'' ), q.IS_NULLABLE2 ) AS FULL_DATA_TYPE
    
    FROM
        q
    WHERE
        q.TABLE_SCHEMA = 'yourSchemaName' AND
        q.TABLE_NAME   = 'yourTableName'  AND 
        q.COLUMN_NAME  = 'yourColumnName'
    
    ORDER BY
        q.TABLE_SCHEMA,
        q.TABLE_NAME,
        q.ORDINAL_POSITION;
    

    Gives results like this:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a c++(preferably MFC) database object that can execute multiple SQL statements(as in
Is there a SQL statement that will list the names of all the tables,
Is there any significance in the order of table in sql join statement. For
Our SSDT database project includes a table that has a computed column that can
There is sql statement select distinct create_date from articles Is it possibele to write
Suppose there is a SQL statement: select * from A order by cola In
Is there any difference between the below 2 CREATE TABLE statements in SQL Server
I have a SQL Select statement where I need to return certain values depending
I would like to execute a Linq to Sql statement that captures the count
Is there a Java equivalent of SQL's COALESCE function? That is, is there any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.