Files
ycc-proxy-server/deploy/sql/template.sql
2025-12-05 18:30:31 +08:00

62 lines
2.9 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ============================================
-- 表结构模板UUID版本
-- ============================================
-- 注意系统已迁移到UUID主键新表请使用此模板
-- ============================================
CREATE TABLE `` (
`id` CHAR(36) NOT NULL COMMENT 'UUID主键',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`delete_time` datetime DEFAULT NULL COMMENT '删除时间',
`del_state` tinyint NOT NULL DEFAULT '0',
`version` bigint NOT NULL DEFAULT '0' COMMENT '版本号',
/* 业务字段开始 */
`1` [] [DEFAULT ] [COMMENT '字段说明'],
`2` [] [DEFAULT ] [COMMENT '字段说明'],
/* 关联字段 - 软关联使用UUID */
`id` CHAR(36) [NOT NULL] [DEFAULT NULL] COMMENT '关联到XX表的UUID',
/* 业务字段结束 */
PRIMARY KEY (`id`),
/* 索引定义 */
UNIQUE KEY `` (``),
KEY `idx_关联字段` (`id`) COMMENT '优化关联查询'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='表说明';
-- ============================================
-- UUID生成说明
-- ============================================
-- 1. 应用层生成使用Go的uuid.NewString()生成UUID
-- 示例id := uuid.NewString()
-- 2. 数据库层生成使用MySQL的UUID()函数(不推荐,性能较差)
-- 示例INSERT INTO table (id, ...) VALUES (UUID(), ...)
-- 3. 推荐方式在应用层生成UUID然后插入数据库
-- ============================================
-- ============================================
-- 旧版本模板bigint主键已废弃
-- ============================================
-- CREATE TABLE `表名` (
-- `id` bigint NOT NULL AUTO_INCREMENT,
-- `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-- `delete_time` datetime DEFAULT NULL COMMENT '删除时间',
-- `del_state` tinyint NOT NULL DEFAULT '0',
-- `version` bigint NOT NULL DEFAULT '0' COMMENT '版本号',
--
-- /* 业务字段开始 */
-- `字段1` 数据类型 [约束条件] [DEFAULT 默认值] [COMMENT '字段说明'],
-- `字段2` 数据类型 [约束条件] [DEFAULT 默认值] [COMMENT '字段说明'],
-- /* 关联字段 - 软关联 */
-- `关联表id` bigint [NOT NULL] [DEFAULT '0'] COMMENT '关联到XX表的id',
-- /* 业务字段结束 */
--
-- PRIMARY KEY (`id`),
-- /* 索引定义 */
-- UNIQUE KEY `索引名称` (`字段名`),
-- KEY `idx_关联字段` (`关联表id`) COMMENT '优化关联查询'
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='表说明';
-- ============================================