第 2 页 共 17 页
目 录
1. 标准版开发数据库设置..........................................................................................................................................................3
2. 命名规范...................................................................................................................................................................................3
.1. 数据库命名规范............................................................................................................................................................3
.1.1. 数据库对象的命名.....................................................................................................................................................3
.1.2. 字段的命名.................................................................................................................................................................4
.1.3. 存储过程的必要注释.................................................................................................................................................4
.2. 数据字典涉及变量命名规范........................................................................................................................................5
.3. 书写 SQL 规范,采用微软的标准规范。...................................................................................................................5
.3.1. 换行 .........................................................................................................................................................................5
.3.2. 空格 .....................................................................................................................................................................5
.3.3. 大小写.........................................................................................................................................................................6
3. 模块脚本配置规范..................................................................................................................................................................7
.4. 脚本复用规定................................................................................................................................................................7
.5. 脚本拆分原则................................................................................................................................................................7
.6. 更新脚本要求可以重复执行........................................................................................................................................7
.7. 在每个脚本开始加入如下代码....................................................................................................................................7
.8. 新增的功能模块提脚本说明........................................................................................................................................8
SQLSERVER SQL 性能优化.............................................................................................................................................8
.1. 选择最有效率的表名顺序(只在基于规则的优化器中有效) .............................................................................8
.2. WHERE 子句中的连接顺序 .................................................................................................................................9
.3. SELECT 子句中避免使用'*'.........................................................................................................................................9
.4. 减少访问数据库的次数。............................................................................................................................................9
.5. 使用 DECODE 函数来减少处理时间 ................................................................................................................10
.6. 用 Where 子句替换 HAVING 子句 .....................................................................................................................11
.7. 减少对表的查询 ..................................................................................................................................................11
.8. 使用表的别名(Alias)...................................................................................................................................................12
.9. 用 EXISTS 替代 IN ..............................................................................................................................................12
.10. 用 NOT EXISTS 替代 NOT IN ..........................................................................................................................13
.11. 用表连接替换 EXISTS ......................................................................................................................................14
.12. 用 EXISTS 替换 DISTINCT ..............................................................................................................................14
.13. 用索引提高效率 ................................................................................................................................................14
.14. 避免在索引列上使用计算 ....................................................................................................................................16
.15. 避免在索引列上使用 IS NULL 和 IS NOT NULL ..........................................................................................16
.16. 使用 UNION-ALL 和 UNION ...........................................................................................................................17
4. 修改历史.................................................................................................................................................................................17