Are there any published coding style guidelines for SQL?

后端 未结 6 1818
感情败类
感情败类 2021-02-12 02:44

Often I will end up with very complex SQL statements and I wondered if there was style guideline out there that dictates a common way of laying various aspects of a query out.

6条回答
  •  不知归路
    2021-02-12 03:16

    Here are some SQL programming guidelines and best practices we collected:

    • Do not use SELECT * in your queries.
    • Always use table aliases when your SQL statement involves more than one source.
    • Use the more readable ANSI-Standard Join clauses instead of the old style joins.
    • Do not use column numbers in the ORDER BY clause.
    • Always use a column list in your INSERT statements.
    • Don't ever use double quotes in your T-SQL code.
    • Do not prefix your stored procedure names with “sp_”.
    • Always use a SQL formatter to format your SQL like Instant SQL Formatter (free and online)

    You can check detailed explanation of those best practices in this blog post.

提交回复
热议问题