Oracle建表,要求主键自增!供参考!

-- Create table
create table T_FTP_OPERATION_LOG
(
  I_ID               INTEGER not null,
  I_MODEL_ID         INTEGER,
  I_USER_ID          INTEGER,
  I_OPERATION_TYPE   INTEGER,
  DTM_OPERATION_TIME DATE
)
tablespace S_NOSS_DEV_USER
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64
    next 1
    minextents 1
    maxextents unlimited
  );
-- Add comments to the columns
comment on column T_FTP_OPERATION_LOG.I_ID
  is '唯一标示,自动增长列';
comment on column T_FTP_OPERATION_LOG.I_MODEL_ID
  is '模板ID';
comment on column T_FTP_OPERATION_LOG.I_USER_ID
  is 'FTP操作人ID';
comment on column T_FTP_OPERATION_LOG.I_OPERATION_TYPE
  is '操作类型1.添加2.修改.3删除';
comment on column T_FTP_OPERATION_LOG.DTM_OPERATION_TIME
  is '操作时间';
-- Create/Recreate primary, unique and foreign key constraints
alter table T_FTP_OPERATION_LOG
  add constraint P_I_ID primary key (I_ID)
  using index
  tablespace S_NOSS_DEV_USER
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Grant/Revoke object privileges
--授权
grant select on T_FTP_OPERATION_LOG to NOSS_TEST;
--建立公共同义词
create or replace public  synonym T_FTP_OPERATION_LOG for noss_dev.T_FTP_OPERATION_LOG;

--建立序列
create sequence T_FTP_OPERATION_LOG_seq
minvalue 1
maxvalue 9999999999
increment by 1
cache 20;
--建立触发器,插入数据时,插入下个序列到主键
create or replace trigger T_FTP_OPERATION_LOG_tri
before insert on T_FTP_OPERATION_LOG
for each row
  begin
    select T_FTP_OPERATION_LOG_seq.Nextval into :new.id from dual;
    end;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26940217/viewspace-733119/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26940217/viewspace-733119/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值