作者:要么永远要么消失_324 | 来源:互联网 | 2014-07-13 17:52
Oracle下实现主键的自增--建表MSHOW_SYSUSER_INFOcreatetableMSHOW_SYSUSER_INFO(IDintprimarykey,ROLE_IDintnotnull,LOGIN_NAMEvarchar2(50)notnull,USER_NAMEvarchar2(20),USER_P..
--建表MSHOW_ SYSUSER_INFO
create table MSHOW_ SYSUSER_INFO
(
ID int primary key,
ROLE_ID int not null,
LOGIN_NAME varchar2(50) not null,
USER_NAME varchar2(20),
USER_PHONE varchar2(20),
USER_DEPARTMENT varchar2(50),
USER_ADDR varchar2(200),
PASSWORD varchar2(50),
CREATE_DATE date,
UPDATE_DATE date,
STATUS int,
RMK varchar2(100)
) www.2cto.com
--创建序列MSHOW_ SYSUSER_INFO_SEQ
CREATE SEQUENCE MSHOW_ SYSUSER_INFO_SEQ
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCACHE
NOCYCLE;
--创建触发器tri_MSHOW_ SYSUSER_INFO
create or replace trigger tri_MSHOW_ SYSUSER_INFO
before insert on MSHOW_ SYSUSER_INFO
for each row
declare
myid number;
begin www.2cto.com
if
:new.ID is null or :new.ID='' or :new.ID=0 then
select MSHOW_ SYSUSER_INFO_SEQ.nextval into myid from dual;
:new.ID:=myid;
end if;
end tri_MSHOW_ SYSUSER_INFO;
摘自 mingyunduoshou的专栏