Created
October 11, 2021 01:53
-
-
Save Sigmanificient/0d7c0a24333b829e051059ff50abe4a8 to your computer and use it in GitHub Desktop.
A mysql routine to insert value within a table and retrieve the pk (with autoincrement)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop function if exists create_server; | |
delimiter $$ | |
CREATE FUNCTION create_server(server_name varchar(50), user_id int) | |
RETURNS int | |
DETERMINISTIC | |
BEGIN | |
INSERT INTO server(name, owner_id) VALUES (server_name, user_id); | |
return last_insert_id(); | |
END $$ | |
delimiter ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment