ORACLE数据库创建表、自增主键、外键相关语法讲解
一 创建表结构:
drop table base_list;
create table base_list (
“data_list_id” number not null ,
“base_data_id” number not null ,
“base_data_list” varchar2(100 byte) not null ,
“flag” number default 0 not null
)
logging
nocompress
nocache
二 创建序列:
create sequence seq_data_list_id– seq_data_list_id 自动增长列
increment by 1 – 每次加几个
start with 1 – 从1开始计数
nomaxvalue – 不设置最大值
nocycle – 一直累加,不循环
nocache
三 创建触发器:
create or replace trigger “bsqam1”.”t_data_list_id” before insert on “bsqam1”.”base_list” referencing old as “old” new as “new” for each row
begin
—在新增之前将自增的主键字段的值赋值为sequence的nextval
select seq_data_list_id.nextval into :new.data_list_id from dual;
end;
四 创建外键:
–使用alter table创建外键
alter table certificate
add constraint f_user_id
foreign key (user_id)
references tuser(user_id);
上一篇: Oracle循环插入数据
下一篇: Matrix Game(尼姆博弈)