数据表设计如下:
-- Create sequence create sequence SEQ_STUDENTminvalue 1maxvalue 999999999999999999999999999start with 1increment by 1cache 20;-- Create sequence create sequence SEQ_STUDENTCLASSminvalue 1maxvalue 999999999999999999999999999start with 1increment by 1cache 20;-- Create tablecreate table STUDENTCLASS( ID NUMBER(10) not null, NAME VARCHAR2(50), CLASSNO VARCHAR2(50), TARGETNUM number(10), REALNUM number(10), BEGINDATE DATE, ENDDATE DATE)tablespace SYSTEM pctfree 10 pctused 40 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited );-- Create/Recreate primary, unique and foreign key constraints alter table STUDENTCLASS add constraint PK_STUDENTCLASS primary key (ID) using index tablespace SYSTEM pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited );
-- Create tablecreate table STUDENT( ID NUMBER(10) not null, TRAININGCOURSE VARCHAR2(50), STUDENTNO VARCHAR2(50), REGISTERDATE DATE, NAME VARCHAR2(50), STUDENTCLASSID NUMBER(10))tablespace SYSTEM pctfree 10 pctused 40 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited );-- Create/Recreate primary, unique and foreign key constraints alter table STUDENT add constraint PK_STUDENT primary key (ID) using index tablespace SYSTEM pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited );alter table STUDENT add constraint FK_STUDENT_STUDENTCLASS foreign key (STUDENTCLASSID) references STUDENTCLASS (ID);
select * from student;select * from studentClass;
insert into studentClass values(SEQ_STUDENTCLASS.Nextval,'javaS1','CRM61T23',30,25,to_date('2012-09-01','yyyy-mm-dd'),to_date('2013-02-01','yyyy-mm-dd'));insert into studentClass values(SEQ_STUDENTCLASS.Nextval,'javaY2','CRM62T23',30,25,to_date('2012-09-01','yyyy-mm-dd'),to_date('2013-02-01','yyyy-mm-dd'));insert into studentClass values(SEQ_STUDENTCLASS.Nextval,'netS1','CRM63T23',30,25,to_date('2012-09-01','yyyy-mm-dd'),to_date('2013-02-01','yyyy-mm-dd'));commit;
insert into student values(seq_student.nextval,'高级java工程师培训','java-1299-001',to_date('2012-09-01','yyyy-mm-dd'),'sam',1);insert into student values(seq_student.nextval,'基础java工程师培训','java-1299-002',to_date('2012-09-01','yyyy-mm-dd'),'john',2);insert into student values(seq_student.nextval,'基础net工程师培训','net-1299-001',to_date('2012-09-01','yyyy-mm-dd'),'joe',3);commit;
select * from student;select * from studentclass;