Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    1 page views
  • 2024, June 28, Friday

#058 Get column data types in Azure SQL

Como obter os tipos de dados das colunas em Consulta (SELECT) existente na linguagem de Manipulação de Dados (DML) do Azure SQL/SQL Server

This T-SQL code queries the information schema information (INFORMATION_SCHEMA. COLUMNS) for details about the columns in all tables in the database. I'll explain each part of the code:

SELECT 
  TABLE_NAME THE 'Table', 
  COLUMN_NAME THE 'Column', 
  DATA_TYPE THE 'Type'
FROM INFORMATION_SCHEMA. COLUMNS 
ORDER BY TABLE_NAME
SELECT TABLE_NAME AS 'Table', COLUMN_NAME AS '
  1. Column', DATA_TYPE AS 'Type'

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • TABLE_NAME AS 'Table': Selects the "TABLE_NAME" column from the information schema and renames it to "Table".
    • COLUMN_NAME AS 'Column': Selects the "COLUMN_NAME" column from the information schema and renames it to 'Column'.
    • DATA_TYPE AS 'Type': Selects the "DATA_TYPE" column of the information schema and renames it to "Type".
  2. FROM INFORMATION_SCHEMA. COLUMNS

    :
    • FROM: Indicates the table or data source from which the data will be selected.
    • INFORMATION_SCHEMA. COLUMNS: It is a view of the system that contains information about the columns of all the tables in the database.
  3. ORDER BY
  4. TABLE_NAME:

    • ORDER BY: Sorts the results of the query.
    • TABLE_NAME: Sorts the results based on the "TABLE_NAME" column, which represents the name of the table.
Therefore, the

code returns information about the columns of all tables in the database, including the table name, column name, and column data type. The results are sorted by the table name. This query is useful for getting an overview of the columns present in the database tables.

This content contains
  • Content Imagem
  • Language Portuguese
  • Duration
  • Subtitles Não

  • Reading time 1 min 20 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now