views:

51

answers:

6

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

+3  A: 

sp_help tablename in sql server

desc tablename in oracle

Pranay Rana
A: 

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

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

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

Pankaj Upadhyay
A: 

In MySQL you can use DESCRIBE <table_name>

Anax
A: 
DESCRIBE tableName

Check MySQL describe command

Amarghosh
A: 

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
Gaby