Describe Table Structure
Which Query Will Give the Table Structure with Column Definitions in Sql? 6 13 Answers Sp_Help Tablename in Sql Server -- Sp_Help [ [ @Objname = ] 'Name' ]...
Which query will give the table structure with column definitions in 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(orsp_columns table_namefor only columns) - Oracle DB2:
desc table_nameordescribe table_name - MySQL:
describe table_name(orshow columns from table_namefor only columns)
In MySQL you can use DESCRIBE <table_name>
select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='<Table Name>'
You can get details like column datatype and size by this query
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'student'
DESCRIBE tableName
Check MySQL describe command
Highlight table name in the console and press ALT+F1
For Sybase aka SQL Anywhere the following command outputs the structure of a table:
DESCRIBE 'TABLE_NAME';
For SQL Server use exec sp_help
USE db_name;
exec sp_help 'dbo.table_name'
For MySQL, use describe
DESCRIBE table_name;
For SQL, use the Keyword 'sp_help'
This depends on your database vendor. Mostly it's the "information schema" you should Google for (applies to MySQL, MSSQL and perhaps others).
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
In DBTools for Sybase, it's sp_columns your_table_name.