This skill should be used when the user asks to "create a table", "design a schema", "write DDL", "generate CREATE TABLE", "build database structure", "generate ER diagram", "draw mermaid ERD", or discusses SQL table design, database schema conventions, audit fields, naming standards, or entity relationship diagrams for database objects.
When the user requests creating tables, designing schemas, writing DDL, or discussing database structure design, the following conventions must be followed.
id as the primary key column, type BIGINTEvery regular table (excluding many-to-many join tables) must include the following columns:
| Column | Type | Constraints | Description |
|---|---|---|---|
| creator | BIGINT | NOT NULL | Creator user ID |
| createDate | DATETIME | NOT NULL, DEFAULT CURRENT_TIMESTAMP | Creation timestamp |
| modifier | BIGINT | NOT NULL | Last modifier user ID |
| modifyDate | DATETIME | NOT NULL, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | Modification timestamp (adjust syntax per RDBMS) |
| removed | BOOLEAN | NOT NULL, DEFAULT FALSE | Soft-delete flag |
<tableName>_id, type BIGINTThe following columns must be indexed:
id (comes with PK, no additional index needed)creator, createDate, modifier, modifyDate, removed<tableName>_id)Index naming convention: idx_<tableName>_<columnName>
INDEX statements must be created outside of the CREATE TABLE statement.
DDL must maintain cross-RDBMS portability. Do not use:
Use only ANSI SQL standard or widely supported syntax.
id, creator, createDate, modifier, modifyDate, removed columns<tableName>_id columns forming a composite primary key<tableA>_<tableB> (e.g., user_role)NOT NULL| Item | Rule | Example |
|---|---|---|
| Table name | Singular + camelCase | userProfile, orderItem |
| Column name | camelCase | createDate, firstName |
| Index name | idx_<tableName>_<columnName> | idx_userProfile_creator |
DECIMAL type (must specify precision, e.g., DECIMAL(19,4))createDate: DEFAULT CURRENT_TIMESTAMPmodifyDate: DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
ON UPDATE, add a comment indicating the application layer must handle thisWHERE removed = FALSEVARCHAR must specify an explicit length limit (e.g., VARCHAR(255))TEXT type for long text contentBIGINT uniformly: primary key id, foreign keys <tableName>_id, creator, modifierWhen outputting DDL, a corresponding Mermaid erDiagram must also be generated for documentation and visualization.
creator, createDate, modifier, modifyDate, removed) are omitted to keep diagrams clean| Symbol | Meaning |
|--------|---------|
| \|\|--o{ | one-to-many |
| \|\|--\|\| | one-to-one |
| \|\|--\|{ | one-to-many (mandatory) |
| o{--o{ | many-to-many (split via join table) |
PK — Primary keyFK — Foreign keybigint, varchar, datetime, boolean, decimal, textCREATE TABLE userProfile (
id BIGINT NOT NULL AUTO_INCREMENT,
firstName VARCHAR(100) NOT NULL,
lastName VARCHAR(100) NOT NULL,
email VARCHAR(255) NOT NULL,
department_id BIGINT NOT NULL,
creator BIGINT NOT NULL,
createDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
modifier BIGINT NOT NULL,
modifyDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
removed BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (id)
);
-- Indexes
CREATE INDEX idx_userProfile_email ON userProfile (email);
CREATE INDEX idx_userProfile_department_id ON userProfile (department_id);
CREATE INDEX idx_userProfile_creator ON userProfile (creator);
CREATE INDEX idx_userProfile_createDate ON userProfile (createDate);
CREATE INDEX idx_userProfile_modifier ON userProfile (modifier);
CREATE INDEX idx_userProfile_modifyDate ON userProfile (modifyDate);
CREATE INDEX idx_userProfile_removed ON userProfile (removed);
CREATE TABLE user_role (
user_id BIGINT NOT NULL,
role_id BIGINT NOT NULL,
PRIMARY KEY (user_id, role_id)
);
-- Indexes
CREATE INDEX idx_user_role_user_id ON user_role (user_id);
CREATE INDEX idx_user_role_role_id ON user_role (role_id);
The following corresponds to the DDL examples above for userProfile, department, role, and the many-to-many join:
erDiagram
department ||--o{ userProfile : "has"
userProfile ||--|{ user_role : "has"
role ||--|{ user_role : "has"
department {
bigint id PK
varchar name
}
userProfile {
bigint id PK
varchar firstName
varchar lastName
varchar email
bigint department_id FK
}
role {
bigint id PK
varchar name
}
user_role {
bigint user_id FK
bigint role_id FK
}
Notes:
user_role) split into two one-to-many relationshipsbigint instead of BIGINT NOT NULL)FK, not PK (even though they form a composite PK in practice)After generating DDL, verify each item:
id BIGINTcreator, createDate, modifier, modifyDate, removed)<tableName>_id, no FK constraintsidx_<tableName>_<columnName> formatReminder: All queries against these tables should default to
WHERE removed = FALSE, unless explicitly querying deleted records.
npx skills add MattAtAIEra/sql-ddl-convention下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer