-
-
Save vorlon001/039b5620e55b3f7c3b3f011990fd291c to your computer and use it in GitHub Desktop.
Create sequence in MySQL
This file contains 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
SET GLOBAL log_bin_trust_function_creators = 1; | |
create database seq; | |
use seq; | |
create table `seq` ( | |
`seq_name` varchar(20) NOT NULL, | |
`last_val` bigint(20) UNSIGNED NOT NULL DEFAULT 1, | |
PRIMARY KEY (`seq_name`) | |
) ENGINE=MyISAM | |
; | |
insert into seq.seq (seq_name) VALUE ('test_ids'); | |
delimiter // | |
create function `get_next_seq_val`(`name` varchar(20)) | |
returns bigint(20) NOT DETERMINISTIC | |
begin | |
update seq set last_val = last_insert_id(last_val + 1) where seq_name = name; | |
return last_insert_id(); | |
end | |
// | |
delimiter ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment