DBAtlas · 数据库运维图谱

显示表的列 / 结构(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

表名以大写形式存储(如果创建时未使用引号)。

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 还会显示索引、约束和外键。

MySQL

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

完整定义使用 SHOW CREATE TABLE customer;(参见下文“生成 DDL”)。

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 除列之外还会列出索引和约束。

MongoDB

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

MongoDB 没有固定 schema;字段可因文档而异。如果定义了 $jsonSchema 验证器,可通过 db.getCollectionInfos 查看。

Redis

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

没有固定 schema;每个键的类型和编码需分别查询。hash 字段使用 HGETALL。

在 DBAtlas 中打开 →