Skip to content
Advertisement

SQL PROCEDURES – Multi inserts

I’m trying to create SQL procedure that registers a user to the system. for that the user details need to save to a lot of tables, i make this procedure and its work but returns me an error:

here is my procedore:

Advertisement

Answer

This code is the problem:

SET @user_uniqe_id = (SELECT ID FROM users WHERE EMAIL=email);

You think that one of the emails is referring to the parameter. But it is not. The where clause is comparing the column to itself.

I recommend giving parameters names that cannot be confused with columns:

This still isn’t really the correct way to do this. You should be using last_insert_id(). That would look like:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement