Files
workspace/code/fms/FMS新系统核心表结构设计.md
T
2026-09-10 17:38:53 +08:00

563 lines
27 KiB
Markdown
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.
**本系统以 SQL 为核心驱动。设计时应优先保证查询和数据处理的灵活性,并在各模块预留 SQL 扩展能力,支持传入 SQL、动态拼接查询条件、组合查询及自定义数据处理逻辑,以便通过 SQL 快速适配和解决复杂业务场景。**
# 数据表规范
本规范用于指导 AI 设计、新增和调整数据库表结构。除非已有表结构或业务要求明确指定,否则应优先遵循以下约定。
1. **表名规范**
- 统一使用小写 `snake_case` 命名,单词之间使用下划线分隔。
- 系统配置、元数据和权限相关表使用 `s_` 前缀,例如 `s_module`、`s_field`。
- 业务数据表使用 `b_` 前缀或明确的业务域前缀,例如 `b_user`、`cw_fee`。
- 表名应表达稳定的业务含义,避免使用页面名称、路由名称或临时功能名称作为表名。
2. **表职责规范**
- 一张表应围绕一个明确的业务对象、配置对象或关系对象设计。
- 系统表用于保存系统配置、元数据、权限和运行记录;业务表用于保存具体业务数据;关系表用于表达对象之间的关联关系。
- 不要为了适配单个页面重复创建业务表;页面差异优先通过模块配置、字段布局和 SQL 组合实现。
3. **主键和关联字段规范**
- 每张表必须定义稳定、明确的主键。业务对象优先使用 `b_id` 作为业务编码主键;关系表可根据业务关系使用联合主键。
- 表之间的关联字段统一使用 `<对象>_id` 或已有的 `b_module_id` 等明确命名,不使用无法判断来源的通用字段名。
- 主键和关联字段的数据类型、长度必须保持一致。
4. **字段命名规范**
- 字段统一使用小写 `snake_case` 命名。
- 主表或主业务对象字段使用 `b_` 前缀;明细、子表或扩展业务字段使用 `mx_` 前缀。
- 系统公共字段沿用现有命名,例如 `b_id`、`b_name`、`b_bz`、`b_canuse`、`b_xh`。
- 字段名应表达业务含义,避免使用 `value`、`data`、`type1` 等无法说明用途的名称;同一含义在不同表中应使用统一命名。
5. **通用字段规范**
- 启用/停用统一使用 `b_canuse`,取值为 `0/1`。
- 排序字段统一使用 `b_xh`,默认值为 `0`;需要稳定排序时增加业务主键作为次排序字段。
- 名称、备注和多语言文本使用 `nvarchar`;编码、状态、类型和 SQL 标识类字段使用 `varchar`。
- 日期时间优先使用 `datetime2`;金额、数量等数值字段根据业务精度明确设置 `precision` 和 `scale`。
- 是否允许为空、默认值和数据库默认值必须根据业务语义明确设置,不能无理由全部允许为空或全部设置默认值。
6. **字段与布局规范**
- 数据字段定义、列表布局、编辑布局和查询布局分开保存,避免把页面展示规则硬编码到业务表中。
- 字段配置、字段分组和用户个性化配置必须通过 `b_module_id` 与所属数据模块关联。
- 页面差异优先通过字段布局、查询条件和 SQL 组合实现,不通过复制数据表实现。
7. **SQL 驱动规范**
- 查询和数据处理应优先采用可组合的 SQL 方案,避免把业务逻辑固化在单个页面或固定查询中。
- 各模块应预留 SQL 扩展入口,支持传入 SQL、动态拼接 `where` 条件、选择字段、排序、分页、关联查询和组合查询。
- 当通用配置无法覆盖业务场景时,优先通过 SQL 视图、查询 SQL、条件片段或数据处理 SQL 扩展,不要立即新增重复表或重复模块。
- SQL 参数、查询字段、排序字段和关联关系应使用明确的元数据或配置进行描述,保证 AI 能够根据模块定义生成和组合查询。
8. **索引和约束规范**
- 主键、外键关联字段、常用查询条件、排序字段和唯一业务键应根据实际查询场景建立索引。
- 索引应服务于明确的查询或关联场景,避免无依据地为每个字段单独建索引。
- 数据库层只保留主键、联合主键、索引和必要的唯一约束;唯一约束可用于保证业务键或组合业务键不重复。
- 除主键、唯一约束和索引外,不增加 `CHECK`、触发器等业务规则约束。字段取值、字段组合、状态流转和其他业务校验统一交给业务层处理。
- 非空和默认值属于字段定义的一部分,应根据业务语义设置;不要使用数据库约束代替业务逻辑。
# FMS 新系统核心表结构
## 1. 用户表
```sql
-- 用户表
create table dbo.b_user (
b_id varchar(50) not null primary key, -- 用户编码(业务键主键)
b_name nvarchar(100) null, -- 用户名
b_bz nvarchar(400) null, -- 备注
b_password nvarchar(255) not null, -- 密码
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_logintime tinyint not null default 0 -- 登录次数
);
```
## 2. 模块
```sql
-- 模块配置表
create table dbo.s_module (
b_id varchar(50) not null primary key, -- 模块编码(业务键主键)
b_parent_id varchar(50) null, -- 父级模块编码,NULL 表示根节点
b_name nvarchar(200) not null, -- 模块名称
b_i18n varchar(150) null, -- 多语言资源键
b_module_type varchar(20) not null, -- 模块类型
b_viewtable varchar(128) null, -- 视图表名(列表查询主表)
b_savetable varchar(128) null, -- 保存表名(写入目标表)
b_keyfield varchar(50) null, -- 主键字段
b_orderfield varchar(500) null, -- 排序字段
b_delete_policy varchar(20) null, -- 删除策略
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_xh int not null default 0, -- 显示顺序
b_bz nvarchar(2000) null, -- 备注
b_edit_mode varchar(10) null -- 编辑模式
);
create index ix_s_module_parent
on dbo.s_module (b_parent_id, b_xh, b_canuse, b_id);
create index ix_s_module_order
on dbo.s_module (b_xh, b_id);
create index ix_s_module_savetable
on dbo.s_module (b_savetable);
```
## 3. 字段和字段布局
```sql
-- 字段定义表
create table dbo.s_field (
b_module_id varchar(50) not null, -- 所属模块编码
b_field varchar(50) not null, -- 字段名
b_name nvarchar(200) not null, -- 字段名称
b_i18n varchar(150) null, -- 多语言资源键
b_type varchar(30) not null, -- 字段类型(业务类型)
b_dbtype varchar(30) not null, -- 数据库类型
b_length int null, -- 长度
b_precision int null, -- 精度
b_scale int null, -- 小数位
b_nullable tinyint not null default 1, -- 是否可空(0/1)
b_default_value nvarchar(1000) null, -- 默认值
b_db_default nvarchar(1000) null, -- 数据库默认值
b_writemode varchar(20) not null default 'direct', -- 写入模式
b_options nvarchar(max) null, -- 选项(下拉等)
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_xh int not null default 0, -- 显示顺序(同步字段时按视图列序重排,10 起步)
primary key (b_module_id, b_field)
);
create index ix_s_field_module_order
on dbo.s_field (b_module_id, b_xh, b_field);
-- 字段分组表
create table dbo.s_field_group (
b_id varchar(50) not null, -- 分组编码
b_module_id varchar(50) not null, -- 所属模块编码
b_parent_id varchar(50) null, -- 父级分组编码,NULL 表示根节点
b_title nvarchar(200) not null, -- 分组标题
b_i18n varchar(150) null, -- 多语言资源键
b_xh int not null default 0, -- 显示顺序
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_colspan int not null default 48, -- 列跨度
b_layout_direction varchar(10) null default 'vertical', -- 布局方向(vertical/horizontal)
primary key (b_module_id, b_id)
);
create index ix_s_field_group_parent
on dbo.s_field_group (b_module_id, b_parent_id, b_xh, b_id);
create index ix_s_field_group_order
on dbo.s_field_group (b_module_id, b_xh, b_id);
-- 列表视图字段配置表
create table dbo.s_field_view (
b_module_id varchar(50) not null, -- 所属模块编码
b_field varchar(50) not null, -- 字段名
b_group_id varchar(50) null, -- 所属分组(同模块 s_field_group.b_id)
b_visible tinyint not null default 1, -- 是否展示(0/1)
b_xh int not null default 0, -- 显示顺序
b_width int null, -- 列宽
primary key (b_module_id, b_field)
);
create index ix_s_field_view_order
on dbo.s_field_view (b_module_id, b_xh, b_field);
-- 编辑字段配置表
create table dbo.s_field_edit (
b_module_id varchar(50) not null, -- 所属模块编码
b_field varchar(50) not null, -- 字段名
b_group_id varchar(50) null, -- 所属分组(同模块 s_field_group.b_id)
b_visible tinyint not null default 1, -- 是否展示(0/1)
b_required tinyint not null default 0, -- 是否必填(0/1)
b_readonly tinyint not null default 0, -- 是否只读(0/1)
b_disabled tinyint not null default 0, -- 是否禁用(0/1)
b_xh int not null default 0, -- 显示顺序
b_width int null, -- 宽度
b_placeholder nvarchar(400) null, -- 占位提示
b_colspan int not null default 12, -- 列跨度
b_height int null, -- 高度
primary key (b_module_id, b_field)
);
create index ix_s_field_edit_order
on dbo.s_field_edit (b_module_id, b_xh, b_field);
-- 查询字段配置表
create table dbo.s_field_query (
b_module_id varchar(50) not null, -- 所属模块编码
b_field varchar(50) not null, -- 字段名
b_component varchar(30) null, -- 查询组件
b_condition_no int not null default 1, -- 条件序号
b_operator varchar(20) not null, -- 操作符
b_default_value nvarchar(1000) null, -- 默认值
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_xh int not null default 0, -- 显示顺序
primary key (b_module_id, b_field, b_condition_no)
);
create index ix_s_field_query_order
on dbo.s_field_query (b_module_id, b_xh, b_field, b_condition_no);
```
## 4. 用户个性化
```sql
-- 用户字段偏好表
create table dbo.s_user_field_pref (
b_user_id varchar(50) not null, -- 用户编码
b_module_id varchar(50) not null, -- 模块编码
b_field varchar(50) not null, -- 字段名
b_mode varchar(10) not null, -- 模式(view / edit)
b_visible tinyint not null default 1, -- 是否展示(0/1)
b_xh int not null default 0, -- 显示顺序
b_width int null, -- 列宽
b_updatedatetime datetime2 null, -- 最后更新时间
primary key (b_user_id, b_module_id, b_field, b_mode)
);
create index ix_s_user_field_pref_order
on dbo.s_user_field_pref (b_user_id, b_module_id, b_mode, b_xh, b_field);
-- 用户查询字段偏好表
create table dbo.s_user_query_field_pref (
b_user_id varchar(50) not null, -- 用户编码
b_module_id varchar(50) not null, -- 模块编码
b_field varchar(50) not null, -- 字段名
b_quick_visible tinyint not null default 1, -- 普通查询收起态是否显示(0/1)
b_xh int not null default 0, -- 显示顺序
b_updatedatetime datetime2 null, -- 最后更新时间
primary key (b_user_id, b_module_id, b_field)
);
create index ix_s_user_query_field_pref_order
on dbo.s_user_query_field_pref (b_user_id, b_module_id, b_xh, b_field);
```
## 5. 自动编码
```sql
-- 自动编码表
create table dbo.s_autocode (
b_module_id varchar(50) not null, -- 模块编码
b_field varchar(50) not null, -- 字段名
b_prefix nvarchar(200) not null default N'', -- 编码前缀
b_dateformat varchar(30) not null default 'yyyyMM', -- 日期格式
b_separator nvarchar(20) not null default N'-', -- 分隔符
b_seqwidth int not null default 5, -- 序号宽度
b_resettype varchar(10) not null default 'month', -- 重置类型
b_startvalue bigint not null default 1, -- 起始值
b_currentperiod varchar(8) null, -- 当前周期
b_currentvalue bigint not null default 0, -- 当前值
b_canuse tinyint not null default 1, -- 是否启用(0/1)
primary key (b_module_id, b_field)
);
```
## 6. 模块关系
```sql
-- 模块关系表
create table dbo.s_relation (
b_module_id varchar(50) not null, -- 源模块编码
b_target_module_id varchar(50) not null, -- 目标模块编码
b_relation_type varchar(20) not null, -- 关系类型
b_field varchar(50) not null, -- 源字段
b_target_field varchar(50) not null, -- 目标字段
b_foreign_side varchar(10) null, -- 外键侧
b_junction_module_id varchar(50) null, -- 中间表模块编码
b_junction_field varchar(50) null, -- 中间表字段
b_junction_target_field varchar(50) null, -- 中间表目标字段
b_ownership varchar(20) not null default 'reference', -- 归属关系
b_owner_side varchar(10) null, -- 属主侧
b_delete_policy varchar(20) null, -- 删除策略
b_order_module_id varchar(50) null, -- 排序模块编码
b_order_field varchar(50) null, -- 排序字段
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_xh int not null default 0, -- 显示顺序
primary key (b_module_id, b_field, b_target_module_id, b_target_field)
);
create index ix_s_relation_module
on dbo.s_relation (b_module_id, b_canuse, b_xh, b_field, b_target_module_id);
create index ix_s_relation_target
on dbo.s_relation (b_target_module_id);
```
## 7. 菜单
```sql
-- 菜单表
create table dbo.s_menu (
b_id varchar(50) not null primary key, -- 菜单编码(业务键主键)
b_parent_id varchar(50) null, -- 父级菜单编码,NULL 表示根节点
b_name nvarchar(200) not null, -- 菜单名称
b_i18n varchar(150) null, -- 多语言资源键
b_menu_type varchar(20) not null, -- 菜单类型
b_route varchar(200) null, -- 路由
b_icon varchar(50) null, -- 图标
b_xh int not null default 0, -- 显示顺序
b_canuse tinyint not null default 1 -- 是否启用(0/1)
);
create index ix_s_menu_parent
on dbo.s_menu (b_parent_id, b_xh, b_canuse, b_id);
create index ix_s_menu_order
on dbo.s_menu (b_xh, b_id);
create index ix_s_menu_route
on dbo.s_menu (b_route, b_canuse, b_id);
```
## 8. 权限
权限定义与用户授权分开,但不增加菜单等级或权限计算中间表:
- `s_power` 是权限点字典,定义系统中可以授予的权限。菜单入口权限使用 `menu.<菜单编码>.access`,模块权限使用 `module.<模块编码>.<operation>`;菜单权限仍然通过 `s_power` 定义,不另建菜单权限字典;
- `s_menu_module` 只描述一个业务页面使用哪些模块,不直接授予用户权限;页面与模块的父子授权关系由授权界面统一处理,不在关系表中增加额外的必需标记或权限等级。
- `s_user_power` 保存用户直接拥有的权限记录,客户授权界面可以维护这张表;菜单页面只是按业务场景组织这些权限,不产生另一套授权来源;
- 同一个模块被多个菜单引用时,页面中展示的是同一个模块权限。模块权限记录只保存一份,撤销某个菜单入口不会自动删除该模块权限。
- 授权界面按“菜单 → 页面模块 → 模块能力”展示父子层级,使用父子级联勾选和半选状态;级联只是配置交互,最终仍保存为各权限点对应的 `s_user_power` 记录。
```sql
-- 菜单模块关联表
create table dbo.s_menu_module (
b_menu_id varchar(50) not null, -- 菜单编码,引用 s_menu.b_id
b_module_id varchar(50) not null, -- 模块编码,引用 s_module.b_id
b_xh int not null default 0, -- 页面内模块顺序
b_canuse tinyint not null default 1, -- 是否启用(0/1)
primary key (b_menu_id, b_module_id)
);
create index IX_s_menu_module_module
on dbo.s_menu_module (b_module_id, b_canuse, b_menu_id);
```
```sql
-- 权限表
create table dbo.s_power (
b_id varchar(100) not null, -- 权限编码即主键
b_name nvarchar(200) not null, -- 权限名称
b_i18n varchar(150) null, -- 多语言资源键
b_power_type varchar(20) not null, -- 权限类型(page / menu / module / action / report)
b_owner_type varchar(20) not null, -- 归属类型(menu / module)
b_owner_id varchar(50) not null, -- 归属对象编码
b_operation varchar(30) not null, -- 权限操作(access / read / create / update / delete / export / audit...)
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_xh int not null default 0, -- 显示顺序
primary key (b_id)
);
create index ix_s_power_owner
on dbo.s_power (b_power_type, b_owner_type, b_owner_id, b_operation, b_canuse);
```
```sql
-- 用户权限表
create table dbo.s_user_power (
b_user_id varchar(50) not null, -- 用户编码
b_power_id varchar(100) not null, -- 权限编码(s_power.b_id)
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_updatedatetime datetime2 null, -- 最后更新时间
primary key (b_user_id, b_power_id)
);
create index ix_s_user_power_user
on dbo.s_user_power (b_user_id, b_canuse, b_power_id);
```
`s_user_power` 的授权约定:
- 菜单入口权限由 `s_power` 定义为 `menu.<菜单编码>.access`,授权时直接写入对应用户的 `s_user_power`;
- 模块查看、新增、修改、删除、导出及业务动作同样由 `s_power` 定义,授权时直接写入对应用户的 `s_user_power`;
- 客户界面可以在菜单页面下同时勾选入口权限和页面所用模块的权限,但保存的仍是同一张 `s_user_power` 表;
- 页面只是配置展示层,后端执行时按权限编码和 `s_menu_module` 校验当前菜单使用的模块;角色表暂不在本阶段引入。
```sql
-- 用户字段权限表
create table dbo.s_user_field_permission (
b_user_id varchar(50) not null, -- 用户编码
b_module_id varchar(50) not null, -- 模块编码
b_field varchar(128) not null, -- 字段名
b_access_mode varchar(10) not null, -- 访问模式(hidden / view / edit)
b_allow_query tinyint not null default 0, -- 是否允许查询(0/1)
b_allow_export tinyint not null default 0, -- 是否允许导出(0/1)
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_updatedatetime datetime2 null, -- 最后更新时间
primary key (b_user_id, b_module_id, b_field)
);
create index ix_s_user_field_permission_module
on dbo.s_user_field_permission (b_user_id, b_module_id, b_canuse, b_field);
```
```sql
-- 用户数据范围表
create table dbo.s_user_data_scope (
b_user_id varchar(50) not null, -- 用户编码
b_module_id varchar(50) not null, -- 模块编码
b_operation varchar(30) not null, -- 操作(* / read / create / update / delete / export)
b_scope_level varchar(10) not null default 'default', -- 范围级别(default / override)
b_scope_no int not null default 1, -- 范围序号
b_scope_type varchar(30) not null, -- 范围类型(own / department / department_tree / all / custom)
b_scope_field varchar(50) null, -- 业务数据中的归属用户/部门字段
b_scope_value varchar(100) null, -- custom 时每个用户/部门值一行
b_updatedatetime datetime2 null, -- 最后更新时间
primary key (b_user_id, b_module_id, b_operation, b_scope_level, b_scope_no),
constraint ck_s_user_data_scope_level check (b_scope_level in ('default','override')),
constraint ck_s_user_data_scope_operation check (
(b_scope_level = 'default' and b_operation = '*')
or (b_scope_level = 'override' and b_operation in ('read','create','update','delete','export'))
)
);
create index ix_s_user_data_scope_module
on dbo.s_user_data_scope (b_user_id, b_module_id, b_operation, b_scope_level, b_scope_type);
```
## 9. 多语言
```sql
-- 多语言类型表
create table dbo.s_i18n_type (
b_id varchar(20) not null primary key, -- 类型编码
b_name nvarchar(200) not null, -- 类型名称
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_default tinyint not null default 0, -- 是否默认(0/1)
b_xh int not null default 0 -- 显示顺序
);
-- 多语言资源表
create table dbo.s_i18n (
b_id varchar(200) not null primary key, -- 资源编码(b_key + ':' + b_locale)
b_key varchar(150) not null, -- 资源键
b_locale varchar(20) not null, -- 语言区域
b_value nvarchar(1000) not null, -- 值
b_i18ntype varchar(20) null, -- 多语言类型
b_canuse tinyint not null default 1, -- 是否启用(0/1)
b_module_id varchar(50) null, -- 模块编码
unique (b_key, b_locale)
);
create index ix_s_i18n_module_key
on dbo.s_i18n (b_module_id, b_key, b_locale);
create index ix_s_i18n_locale
on dbo.s_i18n (b_locale, b_canuse);
```
## 10. 日志
```sql
-- 技术日志表
create table dbo.s_log_technical (
b_id uniqueidentifier not null, -- 日志ID(UUIDv7)
b_user_id varchar(50) null, -- 用户编码(未认证请求时为 NULL)
b_sourcetype varchar(20) null, -- 来源类型
b_loglevel varchar(16) not null, -- 日志级别
b_logcategory varchar(64) null, -- 日志分类
b_operation varchar(100) null, -- 操作
b_module_id varchar(50) null, -- 模块编码
b_request_id varchar(64) null, -- 请求ID
b_trace_id varchar(64) null, -- 链路ID
b_server_node varchar(128) null, -- 服务器节点
b_duration_ms bigint null, -- 耗时(毫秒)
b_result_code varchar(50) null, -- 结果码
b_error_code varchar(50) null, -- 错误码
b_error_message nvarchar(4000) null, -- 错误信息
b_exception_text nvarchar(max) null, -- 异常文本
b_context_text nvarchar(max) null, -- 上下文文本
b_occurdatetime datetime2 default sysutcdatetime(), -- 发生时间
constraint pk_s_log_technical primary key nonclustered (b_id)
);
-- 登录日志表
create table dbo.s_log_login (
b_id uniqueidentifier not null, -- 日志ID(UUIDv7)
b_user_id varchar(50) null, -- 用户编码(账号不存在时为 NULL)
b_login_type varchar(20) not null, -- 登录类型
b_login_result tinyint not null default 0, -- 登录结果(0/1)
b_fail_reason nvarchar(400) null, -- 失败原因
b_ip varchar(50) null, -- IP
b_ip_location nvarchar(400) null, -- IP 归属地
b_browser varchar(100) null, -- 浏览器
b_browser_version varchar(50) null, -- 浏览器版本
b_os varchar(100) null, -- 操作系统
b_os_version varchar(50) null, -- 系统版本
b_device_type varchar(20) null, -- 设备类型
b_user_agent nvarchar(max) null, -- UserAgent
b_session_id varchar(50) null, -- 会话ID
b_request_id varchar(64) null, -- 请求ID
b_trace_id varchar(64) null, -- 链路ID
b_occurdatetime datetime2 default sysutcdatetime(), -- 发生时间
constraint pk_s_log_login primary key nonclustered (b_id)
);
-- 审计日志表
create table dbo.s_log_audit (
b_id uniqueidentifier not null, -- 日志ID(UUIDv7)
b_event_code varchar(50) not null, -- 事件编码
b_module_id varchar(50) null, -- 模块编码
b_data_id varchar(50) null, -- 数据ID
b_business_no varchar(50) null, -- 业务单号
b_operation varchar(100) null, -- 操作
b_operator_id varchar(50) null, -- 操作人ID
b_operator_name nvarchar(200) null, -- 操作人名称
b_source_type varchar(20) not null default 'user', -- 来源类型
b_visibility varchar(20) not null default 'internal', -- 可见性
b_request_id varchar(64) null, -- 请求ID
b_trace_id varchar(64) null, -- 链路ID
b_payload_text nvarchar(max) null, -- 载荷文本
b_occurdatetime datetime2 default sysutcdatetime(), -- 发生时间
constraint pk_s_log_audit primary key nonclustered (b_id)
);
-- 审计字段明细表
create table dbo.s_log_audit_field (
b_id uniqueidentifier not null, -- 日志ID(UUIDv7)
b_event_id uniqueidentifier not null, -- 审计事件ID
b_module_id varchar(50) null, -- 模块编码
b_data_id varchar(50) null, -- 数据ID
b_field varchar(50) not null, -- 字段名
b_field_label nvarchar(200) null, -- 字段标签
b_before_value nvarchar(max) null, -- 变更前值
b_after_value nvarchar(max) null, -- 变更后值
b_before_display nvarchar(1000) null, -- 变更前显示值
b_after_display nvarchar(1000) null, -- 变更后显示值
b_visibility varchar(20) not null default 'internal', -- 可见性
constraint pk_s_log_audit_field primary key nonclustered (b_id)
);
create clustered index cx_s_log_technical_occur
on dbo.s_log_technical (b_occurdatetime, b_id);
create clustered index cx_s_log_login_occur
on dbo.s_log_login (b_occurdatetime, b_id);
create clustered index cx_s_log_audit_occur
on dbo.s_log_audit (b_occurdatetime, b_id);
create clustered index cx_s_log_audit_field_event
on dbo.s_log_audit_field (b_event_id, b_id);
create index ix_s_log_technical_trace
on dbo.s_log_technical (b_trace_id, b_occurdatetime);
create index ix_s_log_login_user
on dbo.s_log_login (b_user_id, b_occurdatetime);
create index ix_s_log_audit_module
on dbo.s_log_audit (b_module_id, b_data_id, b_occurdatetime);
```
## 11. 业务表主键约定
```sql
-- 业务表示例
create table dbo.b_example (
b_id bigint not null primary key, -- 主键(应用层雪花 ID)
b_inputuser_id varchar(50) null, -- 录入用户ID
b_inputdatetime datetime2 default sysutcdatetime() -- 录入时间
);
```