gpt4 book ai didi

php - 插入触发器上的数据库 phpmyadmin

转载 作者:行者123 更新时间:2023-11-30 22:05:38 24 4
gpt4 key购买 nike

有这个SQL。

CREATE TABLE `accounts` (
`account_id` int(3) NOT NULL,
`username` varchar(36) NOT NULL,
`password` varchar(36) NOT NULL,
`email` varchar(60) NOT NULL,
`access_level` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `normal_profile` (
`normal_profileid` int(11) NOT NULL,
`first_name` varchar(64) NOT NULL,
`middle_name` varchar(64) NOT NULL,
`last_name` varchar(64) NOT NULL,
`age` int(2) NOT NULL,
`gender` varchar(6) NOT NULL,
`account_id` int(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `normal_profile`
ADD CONSTRAINT `normal_profile_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`account_id`);

phpmyadmin ui

以上是我设置约束的方式。

每当我在我的帐户表上插入一些东西时,我是否还必须查询插入到 normal_profile 表中?或者我可以自动做到这一点,以便数据库本身只会在 normal_profile 中添加一行,其中 account_id = accounts.account_id?

我对插入约束的内存很模糊,或者我可能记错了?

Adding Trigger UI phpmyadmin

最佳答案

试试这个语法

delimiter #
CREATE TRIGGER after_accounts
AFTER insert ON accounts
FOR EACH ROW
BEGIN
-- your insert query
end#

delimiter ;

enter image description here

关于php - 插入触发器上的数据库 phpmyadmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41868281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com