我很难理解在下面的代码中创建触发器的问题是什么:请帮助。
CREATE TABLE staff (staff_id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
firstname VARCHAR(20)
, lastname VARCHAR(20), email VARCHAR(50));
INSERT INTO staff (firstname, lastname, email)
VALUES ('James', 'Kirby', 'jkirby@test.com'),
('Betty', 'Featherstone', 'bfeatherstone@test.com');
CREATE TABLE users (user_id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
username
VARCHAR(20), email VARCHAR(50),
staff_id INT, FOREIGN KEY (staff_id) REFERENCES staff (staff_id))
DELIMITER //
CREATE TRIGGER after_staff_insert AFTER INSERT ON staff
FOR EACH ROW
BEGIN
INSERT INTO users (username, email)
VALUES(CONCAT(NEW.firstname,NEW.lastname,NEW.staff_id),NEW.email);
END //
DELIMITER;
1条答案
按热度按时间31moq8wy1#
我不能重现你的问题后,我提到的代码块的工作预期的变化。您使用的是什么ide(phpmyadmin、mysqlworkbench)等