CREATE FUNCTION `currval`(seq_name VARCHAR(50)) RETURNS bigint(20)
BEGIN
         DECLARE value BIGINT;
         SELECT current_value INTO value
         FROM cs_sequence
         WHERE upper(name) = upper(seq_name); 
         RETURN value;
END

CREATE FUNCTION `nextval`(seq_name VARCHAR(50)) RETURNS bigint(20)
BEGIN  
         DECLARE value BIGINT;
         UPDATE cs_sequence  
         SET current_value = current_value + increment  
         WHERE upper(name) = upper(seq_name);
         RETURN currval(seq_name);  
END

CREATE FUNCTION `setval`(seq_name VARCHAR(50), value BIGINT) RETURNS bigint(20)
BEGIN 
         UPDATE cs_sequence  
         SET current_value = value  
         WHERE upper(name) = upper(seq_name);  
         RETURN currval(seq_name);  
END
CREATE TABLE `cs_sequence` (
  `Name` varchar(64) NOT NULL,
  `Current_Value` bigint(20) unsigned NOT NULL DEFAULT '0',
  `Increment` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

这是在vjd项目使用的id生成管理方法