Loading...
Loading...
Compare original and translation side by side
Atomic skill for SQL foundations and schema design
用于SQL基础和架构设计的原子技能
parameters:
operation:
type: string
required: true
enum: [create_table, add_constraint, select_type, design_schema]
table_name:
type: string
pattern: "^[a-z][a-z0-9_]*$"
schema:
type: string
default: "public"parameters:
operation:
type: string
required: true
enum: [create_table, add_constraint, select_type, design_schema]
table_name:
type: string
pattern: "^[a-z][a-z0-9_]*$"
schema:
type: string
default: "public"| Use Case | Recommended | Avoid |
|---|---|---|
| Primary key | | |
| Monetary | | |
| Timestamps | | |
| UUID | | |
| JSON data | | |
| 使用场景 | 推荐类型 | 避免使用 |
|---|---|---|
| 主键 | | |
| 货币 | | |
| 时间戳 | | |
| UUID | | |
| JSON数据 | | |
CREATE TABLE schema_name.table_name (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);CREATE TABLE schema_name.table_name (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);-- Foreign key
CONSTRAINT fk_name FOREIGN KEY (col) REFERENCES other(id) ON DELETE CASCADE;
-- Check
CONSTRAINT chk_positive CHECK (amount > 0);
-- Unique
CONSTRAINT uq_email UNIQUE (email);-- 外键
CONSTRAINT fk_name FOREIGN KEY (col) REFERENCES other(id) ON DELETE CASCADE;
-- 检查约束
CONSTRAINT chk_positive CHECK (amount > 0);
-- 唯一约束
CONSTRAINT uq_email UNIQUE (email);| Rule | Pattern |
|---|---|
| Table names | |
| Column names | |
| 规则 | 模式 |
|---|---|
| 表名称 | |
| 列名称 | |
DO $$ BEGIN
DROP TABLE IF EXISTS test_users;
CREATE TABLE test_users (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY);
ASSERT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'test_users');
DROP TABLE test_users;
END $$;DO $$ BEGIN
DROP TABLE IF EXISTS test_users;
CREATE TABLE test_users (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY);
ASSERT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'test_users');
DROP TABLE test_users;
END $$;| Error | Cause | Solution |
|---|---|---|
| Table exists | Use IF NOT EXISTS |
| Duplicate key | Check constraints |
| Column not found | Verify names |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 表已存在 | 使用IF NOT EXISTS |
| 键重复 | 检查约束条件 |
| 列未找到 | 验证名称正确性 |
Skill("postgresql-fundamentals")Skill("postgresql-fundamentals")