Is there any widely used SQL coding standard out there? SQL is little bit different from C/C++ type of programming languages. Really don't know how to best format it for readability.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
From a really very nice blog on PostgreSQL, but this topic is applicable in general:
Maintainable queries - my point of view (depesz.com)
I do agree with capitalization of reserved words and every other identifier, except my own.
Google for sql pretty printer or look here. I haven't tried it out myself, but it gives you a good start. Most commercial tools like Toad have a "formatting" option which helps, too.
Anything in blue is upper case
SELECT
,DELETE
,GO
, etcTable names are singular like the table that holds our customers would be the customer table
Linking tables are
tablename_to_tablename
use
_
between works in table names and parametersexample
I like the comma preceding way:
it makes it the easiest to read and debug in my opinion.
I'm surprised that the coding style I've used for almost 20 years isn't on this list:
I find this the absolutely most readable, but I admit that it is tedious to type. If right aligning the keywords is too much, I'd opt for left aligning them:
This works pretty good for us.
This actual query doesn't make much sense since I tried to build it quickly as an example... but that's not the point.
putting commas at the beginning of the new lines makes it easier to build dynamic queries:
everything else is straightforward.