oracle建表,並設主鍵自增
/* 建立使用者表
*/create table user_info_t(
id integer not null ,
user_id varchar(50),
user_name varchar(50),
user_password varchar(50),
user_*** varchar(20),
user_age integer ,
user_address varchar(50),
user_batch varchar(50),
constraint user_info_t_pk primary key (id)
);/*
建立自增長序列
*/ drop sequence dectuser_tb_seq; /* 若以存在則刪除*/
create sequence dectuser_tb_seq minvalue 1 maxvalue 99999999
increment by 1
start with 1;
/*建立觸發器
*/
create or replace trigger dectuser_tb_tri
before insert on user_info_t /*觸發條件:當向表dectuser執行插入操作時觸發此觸發器*/
for each row /*對每一行都檢測是否觸發*/
begin /*觸發器開始*/
select dectuser_tb_seq.nextval into :new.id from dual; /*觸發器主題內容,即觸發後執行的動作,在此是取得序列dectuser_tb_seq的下乙個值插入到表user_info_t中的id欄位中*/
end;
/* 提交
*/ commit
/*測試
*/insert into user_info_t(user_id,user_name,user_password,user_***,user_age) values ('warren','石頭','warren','m',22);/*插入測試值*/
select * from user_info_t /*查詢*/
建表主鍵自增 Oracle建表,建主鍵,自增
oracle建表,建主鍵,自增 建表 create table test id number 4 not null primary key,name varchar2 25 序列 create sequence test sequence increment by 1 每次增加幾個 start wi...
oracle建表設定主鍵自增
首先建立一張表 create table member memberid number primary key,membermail varchar2 20 not null,membername varchar2 20 not null,memberpassword varchar2 20 然後,...
oracle建表設定主鍵自增
oracle建表設定主鍵自增 首先建立一張表 create table member memberid number primary key,membermail varchar2 20 not null,membername varchar2 20 not null,memberpassword ...