oracle建主键
update imcc.jxdw_v_seat_traffic set sid = rownum; commit;
ALTER TABLE "JXDW_CTI_CALL_LIST" ADD CONSTRAINT PK_JXDW_CTI_CALL_LIST PRIMARY KEY ( "LIST_ID") ENABLE VALIDATE
alter table <table> add contraint pk_table primary key (<column>
oracle没有ORACLE自增字段这样的功能,但是通过触发器(trigger)和序列(sequence)可以实现。
create table t_client (id number(4) primary key,
pid number(4) not null,
name varchar2(30) not null,
client_id varchar2(10),
client_level char(3),
bank_acct_no varchar2(30),
contact_tel varchar2(30),
address varchar2(30),
zip_code varchar2(10),
is_leaf char(1) default 'y' check (is_leaf in('y','n')),
is_client char(1) default 'n' check (is_client in('y','n')
));
假设关键字段为id,建一个序列,代码为:
create sequence seq_t_client_id
minvalue 1
maxvalue 99999999
start with 1
increment by 1
nocache
order;
建解发器代码为:
CREATE OR REPLACE TRIGGER trg_t_client_id
BEFORE INSERT ON t_client
FOR EACH ROW
BEGIN
SELECT seq_t_client_id.nextval INTO :new.id FROM dual;
END;