bulent guven
bulent guven

Reputation: 25

Why does this occurs?

create trigger after_user_register 
before INSERT on Users 
for EACH ROW 
begin 
declare @id integer;
declare @userName varchar(30);
declare @userSurname varchar(30);
select
  @id = userId,
  @userName = userName,
  @userSurname = userSurname
from
  inserted;
insert into
  UsersFullName
values(DEFAULT, @id, concat(@userName, @userSurname)) end

I'm getting #1064 error for the first declaration. Can you help me removing this error.

Upvotes: 0

Views: 64

Answers (1)

Sebastian Brosch
Sebastian Brosch

Reputation: 43574

You have some issues with your CREATE TRIGGER. You can use the following simpler solution:

DELIMITER //

CREATE TRIGGER after_user_register 
AFTER INSERT on Users 
FOR EACH ROW 
  BEGIN 
    INSERT INTO UsersFullName (id, fullname) 
      SELECT new.userId, CONCAT(new.userName, new.userSurname); 
  END 
//

DELIMITER ;

demo: https://www.db-fiddle.com/f/bE5DN43hjX7TtSpS3GDNRn/0

Upvotes: 1

Related Questions