如何编写高效的SQL

1,在select子句中只指定必须的列,不要滥用*
2,避免在索引列上用函数或表达式避免在索引列上用函数或表达式
3,避免使用前置通配符
4,若可以用union all,就避免用union若可以用union all,就避免用union
5,避免对索引列用not,<>,!=
6,尽量用where代替having(需要过滤分组结果时,尽量用Where而非having子句,但where子句中不能使用分组函数)
7,尽量避免用多表连接
8,避免使用耗费资源的操作
9,正确地使用索引

猜你喜欢

转载自blog.csdn.net/afafawfaf/article/details/80968502