创建guid

WBOY
WBOYOriginal
2016-06-07 14:57:391353browse

无详细内容 无 ----用于保存主键CREATE TABLE `c_guid` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL DEFAULT '', `guid` int(11) NOT NULL DEFAULT '1', `desc` varchar(255) DEFAULT NULL, PRIMARY KEY (`Id`), UNIQUE KEY `name`

----用于保存主键
CREATE TABLE `c_guid` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL DEFAULT '',
  `guid` int(11) NOT NULL DEFAULT '1',
  `desc` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=52 DEFAULT CHARSET=utf8;


----如果存在此key,则返回下一个id(既id+1)。否则,创建一条新记录,写入新id为1并返回此id.
CREATE PROCEDURE `nextGUID`(IN p_name varchar(50))
BEGIN    
     insert into c_guid (name,guid) values(p_name,1) ON DUPLICATE KEY UPDATE guid=guid+1;    
     select guid from c_guid where name=p_name;          
END;

call nextGuid('user_pk');
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:ORACLE表分区Next article:SQLServer中的substring函数