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
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

SELECT 
    CatNum, COUNT(CatNum) AS SameRows
FROM
    `vbz-vc`.cat_items
WHERE
    NOT isPulled
GROUP BY CatNum
HAVING SameRows > 1

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

SELECT 
    *
FROM
    cat_items
WHERE
    NOT isPulled AND (CatNum IS NULL)

no Title record

This pulls up active Item records that reference a nonexistent Title record.

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