Oracle 建立表並設定主鍵自增

2021-09-24 12:45:17 字數 925 閱讀 6658

建立資料庫

create table student(id number primary key,

name varchar(200) not null,

*** varchar(200),

create_date date);

指定表名注釋

comment on table student is '學生表';
指定列注釋

comment on column student.id is '學生id';

comment on column student.name is '學生姓名';

comment on column student.*** is '學生性別';

comment on column student.create_date is '建立日期';

建立序列

create sequence student_seq 

increment by 1 -- 每次增加1個

start with 1 --從1開始計數

nomaxvalue -- 不設定最大值

nocycle --直累加,不迴圈

nocache --不建立緩衝區

建立觸發器

create or replace trigger student_trg

before insert on student

for each row -- when (new.id is null) 設定主鍵存在時,不觸發觸發器

begin

select student_seq.nextval into :new.id from dual;

end;

oracle建立表並新增主鍵,設定主鍵自增長

oracle序列詳解和建立自增主鍵 oracle序列主鍵 序列 是oacle提供的用於產生一系列唯一數字的資料庫物件。l 自動提供唯一的數值 l 共享物件 l 主要用於提供主鍵值 l 將序列值裝入記憶體可以提高訪問效率 1.首先建立序列,oracle序列的語法格式為 create sequence ...

Oracle建立表並實現主鍵自增

create table user id number 10 primary key,uname varchar2 50 not null,pwd varchar2 32 tel varchar2 11 email varchar2 50 create sequence user seq incre...

ORACLE表設定主鍵自增

建立表 create table bj zr lngweekreport gascompnt idnumber number primary key,主鍵 自增長 gasname nvarchar2 100 not null,gasratio number 10,2 not null,salesda...