List all Fields in all Tables on SEDE

2

Please login or register to vote for this query.

(click on this box to dismiss)

Lists all columns and their datatypes for all tables in Data Explorer

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT
  TABLE_NAME as [Table],
  ORDINAL_POSITION as [Position],
  COLUMN_NAME as [Column],       
  case 
    when data_type = 'nvarchar'
      then 'nvarchar('+cast(CHARACTER_MAXIMUM_LENGTH as varchar)+')'
    when data_type like '%int%'
      then data_type + '('+cast(NUMERIC_PRECISION as varchar)+')'
    else
      data_type
  end as [Type]
       
FROM   INFORMATION_SCHEMA.COLUMNS;

--all fields:
-- TABLE_SCHEMA = 'dbo'
-- COLUMN_DEFAULT = Null
-- DATETIME_PRECISION = 3 (when DATETIME)
-- NUMERIC_PRECISION_RADIX = (when TINYINT, SMALLINT, INT)
-- NUMERIC_SCALE = Null

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results