How do I return the SQL data types from my query?

前端 未结 13 1459
耶瑟儿~
耶瑟儿~ 2021-01-29 23:58

I\'ve a SQL query that queries an enormous (as in, hundreds of views/tables with hard-to-read names like CMM-CPP-FAP-ADD) database that I don\'t need nor want to understand. Th

相关标签:
13条回答
  • 2021-01-30 00:50

    Checking data types. The first way to check data types for SQL Server database is a query with the SYS schema table. The below query uses COLUMNS and TYPES tables:

        SELECT C.NAME AS COLUMN_NAME,
           TYPE_NAME(C.USER_TYPE_ID) AS DATA_TYPE,
           C.IS_NULLABLE,
           C.MAX_LENGTH,
           C.PRECISION,
           C.SCALE
    FROM SYS.COLUMNS C
    JOIN SYS.TYPES T
         ON C.USER_TYPE_ID=T.USER_TYPE_ID
    WHERE C.OBJECT_ID=OBJECT_ID('your_table_name');
    

    In this way, you can find data types of columns.

    0 讨论(0)
提交回复
热议问题