DBAtlas · Atlas für Datenbankbetrieb

Spalten / Struktur einer Tabelle anzeigen (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

Tabellennamen werden in Großbuchstaben gespeichert (wenn ohne Anführungszeichen angelegt).

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 zeigt auch Indizes, Constraints und Foreign Keys.

MySQL

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

Für die vollständige Definition SHOW CREATE TABLE customer; verwenden (siehe das Konzept „DDL erzeugen“ unten).

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 listet neben den Spalten auch Indizes und Constraints auf.

MongoDB

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

MongoDB hat kein festes Schema; Felder können von Dokument zu Dokument variieren. Ist ein $jsonSchema-Validator definiert, lässt er sich mit db.getCollectionInfos anzeigen.

Redis

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

Es gibt kein festes Schema; Typ und Encoding jedes Keys werden separat abgefragt. Für Hash-Felder HGETALL verwenden.

In DBAtlas öffnen →