½¨Á¢±íÈçÏÂ:
ѧÉú»ù±¾ÐÅÏ¢±í
CREATE Student(
[Studentid][Int]IDENTITY(1,1)NOT NULL primary key,--Ö÷¼ü
[StudentName][char]NOT NULL
)
¿Î³ÌÐÅÏ¢±í
CREATE Subject(
[SubjectID][char]NOT NULL primary key, --Ö÷¼ü
[SubjectName][char]NOT NULL
)
³É¼¨±í
CREATE Grade(
[Studentid][Int]NOT NULL, --ÁªºÏÖ÷¼ü
[SubjectID][char]NOT NULL, --ÁªºÏÖ÷¼ü
[Grade] [INT]NOT NULL,
primary key (studentid,subjectid)
)
1.½«½¨±íÃüÁî¸ÄΪORACLEÓï¾äÔÚORACLEÖн¨±í
create table student( --ѧÉú±í
studentid number(3) primary key, --ѧÉú±àºÅ
studentname varchar2(20) --ѧÉúµÄÐÕÃû
);
create table subject( --¿Î³Ì±í
subjectid char(3) primary key, --¿Î³Ì±àºÅ
subjectname varchar2(20) --¿Î³ÌµÄÃû×Ö
);
create table grade( --·ÖÊý±í
studentid number(3) references student(studentid), --ѧÉúid
subjectid char(3) references subject(subjectid), --¿Î³Ìid
mark number(3), --·ÖÊý
primary key (studentid,subjectid) --ÁªºÏÖ÷¼ü
);
insert into student values (101,'ÕÅÈý');
insert into student values (102,'ÀîÔÆ');
insert into student values (103,'δ');
insert into subject values ('A01','C++');
insert into subject values ('A02','ASP');
insert into subject values ('A03','JAVA');
insert into grade values (101,'A01',59);
insert into grade values (101,'A02',72);
insert into grade values (101,'A03',90);
insert into grade values (102,'A01',75);
insert into grade values (102,'A02',91);
insert into grade values (103,'A01',71);
2.×÷ÈçÏÂ4Ìâ
µÚÒ»ÎÊ£º²éѯ³öÒÔÏÂÐÅÏ¢
ѧºÅ ѧÉúÐÕÃû ¿Î³ÌÃû³Æ ³É¼¨ £¨ÒªÈ«²¿Ñ§ÉúÐÅÏ¢£©
¹ØÁª²éѯ (¶àÕűíµÄ)
±ðÃû
select a.studentid as "ѧ ºÅ",studentname "ѧÉúÐÕÃû",
subjectname "¿Î³ÌÃû³Æ",mark "³É ¼¨"
from student a , subject b , grade c
where a.studentid = c.studentid
and b.subjectid = c.subjectid;
[select a.studentid "ѧ ºÅ",studentname &q