对于sql SERVER数据库实现字段自增比较简单,可以之间使用函数:identity(),例如我们在建表时可以这样实现:
create table tbRentInfo( sID int identity (1,1) primary key not null,sDVDID int not null,sName varchar(20) not null,sDate datetime not null,foreign key (sDVDID) references tbDVDInfo(sDVDID) );
Oracle数据库可以使用:Sequences+触发器来实现:
1、首先建表:
create table tbRentInfo( sID int primary key not null,foreign key (sDVDID) references tbDVDInfo(sDVDID) );
2、建立一个序列:
-- Create sequence create sequence USER_SEQ minvalue 1 maxvalue 9999999999999999999999999999 start with 5 increment by 1 nocache;
3、建立一个触发器:
create or replace trigger tbRentInfo_trigger before insert on tbRentInfo for each row begin select user_seq.nextval into :new.sid from dual; end;搞定了。