DBAtlas · Database operations atlas

Show a table's columns / structure (describe)

Oracle

SELECT column_name, data_type, data_length, nullable
FROM user_tab_columns
WHERE table_name = 'EMPLOYEE'
ORDER BY column_id;
-- Shortcut (SQL*Plus): DESC employee

Table names are stored in uppercase (if created without quotes).

PostgreSQL

SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'customer'
ORDER BY ordinal_position;
-- psql shortcut: \d customer

\d also shows indexes, constraints and foreign keys.

MySQL

DESCRIBE customer;
-- or: SHOW COLUMNS FROM customer;

For the full definition use SHOW CREATE TABLE customer; (see the 'Generate DDL' concept below).

SQL Server

SELECT c.name, t.name AS type, c.max_length, c.is_nullable
FROM sys.columns c
JOIN sys.types t ON c.user_type_id = t.user_type_id
WHERE c.object_id = OBJECT_ID('dbo.customer')
ORDER BY c.column_id;
-- Shortcut: EXEC sp_help 'dbo.customer';

sp_help lists indexes and constraints in addition to columns.

MongoDB

// The schema is flexible; infer it from a sample document:
db.customer.findOne()
// For field coverage: db.customer.aggregate([{ $sample: { size: 100 } }])

MongoDB has no fixed schema; fields can vary from document to document. If a $jsonSchema validator is defined, it can be seen with db.getCollectionInfos.

Redis

TYPE mykey        # string | list | set | hash | zset | stream
OBJECT ENCODING mykey   # internal encoding

There is no fixed schema; the type and encoding of each key are queried separately. Use HGETALL for hash fields.

Open in DBAtlas →