数据库序列和触发器

数据库序列

创建序列

CREATE sequence T_SEG_SEQ minvalue 1000000000 maxvalue 9999999999 START WITH 1000000440 INCREMENT BY 1 cache 20;

创建触发器

CREATE TRIGGER T_SEG_TRI before INSERT ON T_SEG FOR each ROW
BEGIN
    SELECT
        T_SEG_SEQ.nextval INTO:new.ID
    FROM
    dual; END;

使用sql语句建表并设置主键自增

Create table
create table    
(
  ID        VARCHAR2(40) default TO_CHAR("C##CARD_AP"."SEQ_T_EASYVISITOR"."NEXTVAL") not null,
  xm        VARCHAR2(10) not null,
  sfzh      VARCHAR2(15) not null,
  tw        VARCHAR2(15) not null,
  fzjg      VARCHAR2(5) not null,
  mz        VARCHAR2(10) not null,
  bfsj      TIMESTAMP(6) default sysdate not null,
  phone     VARCHAR2(20) not null,
  csrq      TIMESTAMP(6) not null,
  fzsj      TIMESTAMP(6) not null
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table T_EASYVISITOR
  is '访客易信息表';
-- Add comments to the columns 
comment on column T_EASYVISITOR.ID
  is 'ID(主键)自增';
comment on column T_EASYVISITOR.xm
  is '姓名';
comment on column T_EASYVISITOR.sfzh
  is '身份证号';
comment on column T_EASYVISITOR.tw
  is '体温';
comment on column T_EASYVISITOR.fzjg
  is '发证机关';
comment on column T_EASYVISITOR.mz
  is '民族';
comment on column T_EASYVISITOR.bfsj
  is '拜访时间';
comment on column T_EASYVISITOR.phone
  is '电话号码';
comment on column T_EASYVISITOR.csrq
  is '出生日期';
comment on column T_EASYVISITOR.fzsj
  is '发证时间';
-- Create/Recreate primary, unique and foreign key constraints 
alter table T_EASYVISITOR
  add constraint PRI_EASYVISITOR_ID primary key (ID)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
​
​

使用触发器实现主键自增**创建表并设置主键**

Create table
create table T_CITY_BANK_OPEN
(
  cbid        VARCHAR2(40) not null,
  citycode    VARCHAR2(32),
  bankcode    VARCHAR2(16) not null,
  bankname    VARCHAR2(32) not null,
  del         VARCHAR2(5),
  create_time TIMESTAMP(6) default sysdate not null,
  update_time TIMESTAMP(6)
)
tablespace SISP_PUBLIC_TBS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Create/Recreate primary, unique and foreign key constraints 
alter table T_CITY_BANK_OPEN
  add constraint PK_T_CITY_BANK_OPEN primary key (CBID)
  using index 
  tablespace SISP_PUBLIC_TBS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
​
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值