DBAtlas · 数据库运维图谱

生成对象的 DDL(CREATE 语句)

Oracle

SELECT DBMS_METADATA.GET_DDL('TABLE', 'EMPLOYEE', 'HR') FROM dual;

索引使用 'INDEX',包使用 'PACKAGE',依此类推。使用 SET LONG 100000 防止长输出被截断。

PostgreSQL

-- There is no single function in SQL; from the shell:
pg_dump -t public.customer --schema-only mydb

在 psql 中,\d customer 以易读形式显示结构;完整 DDL 使用 pg_dump --schema-only。

MySQL

SHOW CREATE TABLE customer\G

一条命令即可返回完整的 CREATE TABLE(列、索引、引擎、字符集)。

SQL Server

-- T-SQL has no single built-in command. Options:
-- 1) SSMS: right-click > Script Table as > CREATE To
-- 2) EXEC sp_help 'dbo.customer';  (structure summary)
-- 3) mssql-scripter tool (command line)

查看存储过程/视图主体:SELECT OBJECT_DEFINITION(OBJECT_ID('dbo.usp_name'));

MongoDB

// There is no DDL (schemaless). View collection options/validator:
db.getCollectionInfos({ name: "customer" })

如果定义了 options.validator($jsonSchema),它就是唯一的“schema 定义”;索引需通过 getIndexes() 单独获取。

Redis

# Not applicable: there is no schema/DDL concept.

数据结构在应用代码中定义;持久化存储在 RDB/AOF 文件中。

在 DBAtlas 中打开 →