![]() |
Indenting SQL
How do you indent your SQL?
I think there might be a proper standard since Wildhoney separates every clause on different line. |
sql Code:
|
Just hit your <enter> key and use the spacebar to indent. I've not seen a standard per se as to how to properly format SQL statements, but it makes it much more clear (and easy to edit) if it's not all bunched together.
|
I tend to put a tab line in and start each part of the statment on the tab line so if ofen looks like:
Code:
$myquery= "SELECT * FROM tableobviously if its a more complex query it changes with joins and what not but thats my basic format for queries. |
Now, if you're talking about SQL within a PHP script, I find the overall best solution (not in every case, mind you) is to use HEREDOC syntax, e.g.
PHP Code:
Second best method, IMHO is to simply use PHP's ability to ignore whitespace as Pete pointed out. PHP Manual Language Reference | Types : Strings | HEREDOC syntax |
Heredocs aren't great because when you close a heredoc string you must not have any white space in front of it which is a problem is most cases when trying to make your code look clean.
|
I just tend to split mine over multiple lines if it's a long query to make it more readable than 1 long line.
For example: Code:
SELECT `a`.`articleid`, `a`.`title`, `a`.`content`, `m`.* Alan |
Here's how I do it.
sql Code:
|
poor example, but here is how i do it.
Code:
SELECT t1.col1, t1.col2, t3.col3 |
Indenting SQL
SQL standard
In general the SQL92 standard can be followed. Support for this in various databases are in most cases complete. This document will explain in which cases the standard cannot be followed. __________________________________________________ _____________ Want to get-on Google's first page and loads of traffic to your website? Hire a SEO specialist from Ocean Groups seo specialist |
| All times are GMT. The time now is 09:46 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0