VbzCart/tables/cat items/integrity checks

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< VbzCart‎ | tables‎ | cat items
Revision as of 01:44, 2 March 2016 by Woozle (talk | contribs) (this seems worth a separate page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

All of these queries should return with no rows, but there's nothing in the table definition to prevent this from happening.

duplicate CatNum values

<mysql>SELECT

   CatNum, COUNT(CatNum) AS SameRows

FROM

   `vbz-vc`.cat_items

WHERE

   NOT isPulled

GROUP BY CatNum HAVING SameRows > 1</mysql> The supplier catalog build process will check for duplicates to the catalog numbers it suggests for new items, but items entered manually could still have duplicate catalog numbers. Possibly there should be a unique key consisting of (CatNum,isPulled), but that would also prevent duplicate pulled and dumped items, which would be a problem.

blank CatNum values

<mysql>SELECT

   *

FROM

   cat_items

WHERE

   NOT isPulled AND (CatNum IS NULL)</mysql>

no Title record

This pulls up active Item records that reference a nonexistent Title record. <mysql>SELECT

   i.*

FROM

   cat_items AS i
       LEFT JOIN
   cat_titles AS t ON i.ID_Title = t.ID

WHERE

   (t.ID IS NULL) AND NOT isPulled</mysql>