Message-ID: <1845612868.377860.1711645875006.JavaMail.root@confluence-doc2-production> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_377859_1454524922.1711645875001" ------=_Part_377859_1454524922.1711645875001 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html SQL Guidelines

SQL Guidelines

SQL Guidelines

Table names

  1. Table names must begin with the PrestaShop "_DB_PREFIX_= " prefix.

    =20
    ... FROM=
     `'. _DB_PREFIX_.'customer` ...
    
    =20
  2. Table names must have the same name as the object they reflect: "= ps_cart".
  3. Table names have to stay singular: "ps_order".
  4. Language data have to be stored in a table named exactly like the objec= t's table, and with the "_lang" suffix: "ps_product_lang= ".

SQL query

  1. Keywords must be written in uppercase.

    =20
    SELECT `=
    firstname`
    FROM `'._DB_PREFIX_.'customer`
    
    =20
  2. Back quotes ("`") must be used around SQL field names a= nd table names.

    =20
    SELECT p=
    .`foo`, c.`bar`
    FROM `'._DB_PREFIX_.'product` p, `'._DB_PREFIX_.'customer` c
    
    =20
  3. Table aliases have to be named by taking the first letter of each wo= rd, and must be lowercase.

    =20
    SELECT p=
    .`id_product`, pl.`name`
    FROM `'._DB_PREFIX_.'product` p
    NATURAL JOIN `'._DB_PREFIX_.'product_lang` pl
    
    =20
  4. When conflicts between table aliases occur, the second character has= to be also used in the name.

    =20
    SELECT c=
    a.`id_product`, cu.`firstname`
    FROM `'._DB_PREFIX_.'cart` ca, `'._DB_PREFIX_.'customer` cu
    
    =20
  5. A new line has to be created for each clause.

    =20
    $query =
    =3D 'SELECT pl.`name`
    FROM `'._DB_PREFIX_.'product_lang` pl
    WHERE pl.`id_product` =3D 17';
    
    =20
  6. It is forbidden to make a JOIN in a WHERE cla= use.
------=_Part_377859_1454524922.1711645875001--