Search code examples
sqldatabasetable-structure

How can I retrieve the table structure from a sql database?


So basically I want a SQL Command that return every column in the table and the datatype that is in that column and whether is nullable.


Solution

  • You can use information schema.

    SELECT 
      COLUMN_NAME,
      DATA_TYPE, 
      IS_NULLABLE
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'yourTableName'