Describe table structure

SqlDatabase

Sql Problem Overview


Which query will give the table structure with column definitions in SQL?

Sql Solutions


Solution 1 - Sql

sp_help tablename in sql server -- sp_help [ [ @objname = ] 'name' ]

desc tablename in oracle -- DESCRIBE { table-Name | view-Name }

Solution 2 - Sql

It depends from the database you use. Here is an incomplete list:

  • sqlite3: .schema table_name
  • Postgres (psql): \d table_name
  • SQL Server: sp_help table_name (or sp_columns table_name for only columns)
  • Oracle DB2: desc table_name or describe table_name
  • MySQL: describe table_name (or show columns from table_name for only columns)

Solution 3 - Sql

In MySQL you can use DESCRIBE <table_name>

Solution 4 - Sql

select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='<Table Name>'

You can get details like column datatype and size by this query

Solution 5 - Sql

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'student'

Solution 6 - Sql

DESCRIBE tableName

Check MySQL describe command

Solution 7 - Sql

Highlight table name in the console and press ALT+F1

Solution 8 - Sql

For Sybase aka SQL Anywhere the following command outputs the structure of a table:

DESCRIBE 'TABLE_NAME';

Solution 9 - Sql

For SQL Server use exec sp_help

USE db_name;
exec sp_help 'dbo.table_name'

For MySQL, use describe

DESCRIBE table_name;

Solution 10 - Sql

For SQL, use the Keyword 'sp_help' enter image description here

Solution 11 - Sql

This depends on your database vendor. Mostly it's the "information schema" you should Google for (applies to MySQL, MSSQL and perhaps others).

Solution 12 - Sql

Sql server

DECLARE @tableName nvarchar(100)
SET @tableName = N'members' -- change with table name
SELECT
	[column].*,
	COLUMNPROPERTY(object_id([column].[TABLE_NAME]), [column].[COLUMN_NAME], 'IsIdentity') AS [identity]
FROM 
	INFORMATION_SCHEMA.COLUMNS [column] 
WHERE
	[column].[Table_Name] = @tableName

Solution 13 - Sql

In DBTools for Sybase, it's sp_columns your_table_name.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnto VargheseView Question on Stackoverflow
Solution 1 - SqlPranay RanaView Answer on Stackoverflow
Solution 2 - SqlschmijosView Answer on Stackoverflow
Solution 3 - SqlAnaxView Answer on Stackoverflow
Solution 4 - SqlPankaj UpadhyayView Answer on Stackoverflow
Solution 5 - SqlneerajView Answer on Stackoverflow
Solution 6 - SqlAmarghoshView Answer on Stackoverflow
Solution 7 - SqlKrishna TejaView Answer on Stackoverflow
Solution 8 - SqlOzair KafrayView Answer on Stackoverflow
Solution 9 - SqlHari_pbView Answer on Stackoverflow
Solution 10 - SqlmaneeshView Answer on Stackoverflow
Solution 11 - SqlKarel PetranekView Answer on Stackoverflow
Solution 12 - SqlGabriele PetrioliView Answer on Stackoverflow
Solution 13 - SqlQuan VOView Answer on Stackoverflow