並發生成方式

2021-08-19 11:19:39 字數 897 閱讀 8627

並發生成方式:

sequence的並發生成方式同非並發生成方式都需要建立sequence表,如下:

一:建立sequence表:

複製**

drop table

if exists sequence;

create table

sequence

(name varchar(50) not null,

current_value bigint not null,

increment int not null default 1,

primary key (name)

)engine=innodb;

複製**

插入定義的序列:

insert into sequence values ('seq_trz_member_no',10000000000,1);

二:自定義函式實現:

複製**

drop function if exists get_form_defined_seq;  

delimiter $$  

create function get_form_defined_seq(seq_name char (50)) returns bigint

begin

update sequence set current_value=last_insert_id(current_value+increment) where name=seq_name;

return last_insert_id();

end $$

delimiter;

複製**

函式內部呼叫了mysql內部提供的last_insert_id()函式完成併發控制。

show function status 

主鍵生成方式

在做搭建ssh專案時,用hibernate反射機制生成pojo以及對映檔案。表主鍵選擇的是uuid,但是程式執行過程中,就報錯了。結果查資料才發現一些問題。大家平時多注意點。在hibernate2.1中,主鍵生成策略中uuid分為uuid.hex和uuid.string,但是從hibernate3....

GUID生成方式

uniqueidentifier guid 字段 在ms sql 資料庫中可以在建立表結構是指定字段型別為uniqueidentifier,並且其預設值可以使用newid 來生成唯一的guid 全域性唯一識別符號 使用newid生成的比較隨機,如果是sql 2005可以使用newsequential...

oracle主鍵生成方式

oracle主鍵 兩種方法 自增主鍵sequence,sys guid 生成唯一序列。一 自增主鍵 建立乙個表 create table test nid int primary key,test1 varchar2 20 test2 varchar2 20 再建乙個序列seq test creat...