MySQL产品库存数量

时间:2019-01-17 15:53:52

标签: mysql

我有下表:

`produsebon`(  

`id_cmb` int(11) NOT NULL AUTO_INCREMENT,
  `idprd_cmb` int(11) NOT NULL,
  `idbon_cmb` int(11) NOT NULL,
  `cantitate_cmb` int(11) NOT NULL,
  PRIMARY KEY (`id_cmb`),
  KEY `idprd_cmb` (`idprd_cmb`),
  KEY `idbon_cmb` (`idbon_cmb`),
  CONSTRAINT `produsebon_ibfk_1` FOREIGN KEY (`idbon_cmb`) REFERENCES `bon` (`id_bon`),
  CONSTRAINT `produsebon_ibfk_2` FOREIGN KEY (`idprd_cmb`) REFERENCES `produs_prd` (`id_prd`)
)

和这个:

 `produs_prd` (
  `id_prd` int(11) NOT NULL AUTO_INCREMENT,
  `nume_prd` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `descriere_prd` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
  `tip_prd` int(11) NOT NULL,
  `idanm_prd` int(11) NOT NULL,
  `pret_prd` decimal(13,2) NOT NULL,
  `stoc_prd` int(11) NOT NULL,
  `imagine_prd` varchar(255) NOT NULL,
  PRIMARY KEY (`id_prd`),
  KEY `idanm_prd` (`idanm_prd`),
  KEY `tip_prd` (`tip_prd`),
  CONSTRAINT `produs_prd_ibfk_2` FOREIGN KEY (`tip_prd`) REFERENCES `produs_type` (`id_ptp`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `produs_prd_ibfk_3` FOREIGN KEY (`idanm_prd`) REFERENCES `animals_anm` (`id_anm`) ON DELETE CASCADE ON UPDATE CASCADE
)

因此,基本上,这是一家商店(项目4 uni)的数据库,我想以这种方式在购买产品时(将其移动到cantitate_cmb列上的produse_bon表中,该表将反映购买的产品),则(produs_prd).stoc_prd会减少用户“购买”的金额。

在php中做起来很简单,但是有没有办法让SGBD做到这一点呢?像事件处理程序还是函数?

0 个答案:

没有答案