Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use the following rules:</p> <ul> <li>Always uppercase sql reserved words (SELECT, FROM, WHERE, HAVING, AND, OR, DISTINCT etc.)</li> </ul> <p><UL>Ugly:<BR> <code>select height,width,age from person where width = 20</code><BR> Tidy:<BR> <code>SELECT height, width, age FROM person WHERE (width = 20)</code><BR> </UL></p> <ul> <li><p>Lowercase all table names. Never use camelcase (donkeyWrench) in table names (you will shoot yourself in the head if you create the queries by hand).</p></li> <li><p>Always use parentheses at WHERE and HAVING clauses. Use space between operators.</p></li> </ul> <p><UL>Ugly:<BR> <code>... where width=20 and height&gt;20</code><BR> Tidy:<BR> <code>WHERE (width = 20) AND (height &gt; 20)</code><BR> </UL></p> <ul> <li>Use aliases for tablenames.</li> </ul> <ul> `SELECT * FROM donkeywrench dw ...` </ul> <ul> <li>Use readable, tablename related primary key fields. I always start keys and primary keys with 'id_'.</li> </ul> <ul> tablename: donkeywrench, primary key: id_donkeywrench </ul> <ul> <li>Mark where the query originated from. While reading logs you can easily track down where the problem occured.</li> </ul> <ul> /*Called from donkeykong.php, line 22*/ SELECT * FROM donkeywrench dw ... </ul> <ul> <li>If the query is loooong</li> </ul> <ul> - Always leave the operator (AND, OR) at the end of the line<BR> - Use parentheses!<BR> </ul> <p>Example: <BR></p> <pre><code>/*Executed from xyz.php*/ SELECT p.height, p.width, p.age, pd.hastel, pd.hasmobile FROM person p LEFT JOIN personaldata pd ON p.id_person = pd.id_person LEFT JOIN relatives r ON pd.id_person = r.id_person WHERE ( p.width = 20 ) AND ( (p.height &gt; 20) AND (p.height &lt; 15) ) AND ( pd.hastel) ORDER BY p.age, p.height </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload