what is the proper way to do unsigned parameter in mysql stored procedures

mysql, stored-procedures

Solution

Just add the word `unsigned`. I removed the `(10)` just because it's irrelevant. It just describes how much digits shall be shown, but it's always an int with 4 bytes.

CREATE PROCEDURE `unrollme_version3`.`del_user` (in v_user_id int unsigned)
BEGIN
START TRANSACTION; 
    DELETE FROM user_table1 WHERE `user_id` = v_user_id;
    DELETE FROM user_table2 WHERE `user_id` = v_user_id;
    DELETE FROM user_table3 WHERE `user_id` = v_user_id;
COMMIT;
END

You can force to throw an error instead of a warning by doing

SET sql_mode='STRICT_ALL_TABLES';

For more information see the manual.

Problem

I have a procedure to delete a user information from all the tables in our database. ``` CREATE PROCEDURE `unrollme_version3`.`del_user` (in v_user_id int(10)) BEGIN START TRANSACTION; DELETE FROM user_table1 WHERE `user_id` = v_user_id; DELETE FROM user_table2 WHERE `user_id` = v_user_id; DELETE FROM user_table3 WHERE `user_id` = v_user_id; COMMIT; END ``` i would like to in someway make the input variable only unsigned to match how the structure of the database is setup. is this possible and what is the best practice.

Original source