• [^] # Re: structure

    Posté par (site web personnel, Mastodon) . En réponse au message Sous requêtes et alias. Évalué à 3.

    +1
    Je m’attendais à avoir, dans ce cas simple, une table de liaison

    CREATE TABLE
     Etats (
     produit INTEGER NOT NULL REFERENCES Produits (id),
     emplacement INTEGER NOT NULL REFERENCES Emplacements (id),
     stock INTEGER NOT NULL DEFAULT 0,
     PRIMARY KEY (produit, emplacement)
     );

    et pour tracer/historiciser les mouvements (mais est-ce vraiment nécessaire ?)

    CREATE TABLE
     Mouvements (
     produit INTEGER NOT NULL REFERENCES Produits (id),
     quantite INTEGER NOT NULL DEFAULT 1 CHECK (quantite >= 1),
     origine INTEGER NOT NULL REFERENCES Emplacements (id),
     destination INTEGER NOT NULL REFERENCES Emplacements (id),
     moment DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
     PRIMARY KEY (moment, produit),
     -- on peut remplacer moment ici ou le completer par origine,destination
     CHECK (origine != destination)
     );

    "It is seldom that liberty of any kind is lost all at once." ― David Hume