Question

9 We want to find out the courses that each student is not enrolled in. Give a listing of the course descriptions, and the students (lname) who are not taking that specific course (Use a cartesi...

9

We want to find out the courses that each student is not enrolled in.

Give a listing of the course descriptions, and the students (lname) who are not taking that specific course

(Use a cartesian product and union it with a minus)

drop table student_class;
drop table student;
drop table class;

create table student
(
ssn char(11) not null,
lname varchar(40) not null,
fname varchar(20) not null,
phone char(12),
address varchar(40),
city varchar(20),
state char(2),
zip char(5),
dob date,
salary number
);

create table class
(
   class_code varchar2(10),
   class_description varchar2(30)
);

create table student_class
(
   ssn char(11) not null,
   class_code varchar2(10) not null  
);


alter table student add constraint student_pk primary key (ssn);
alter table student_class add constraint stu_cla_pk primary key(ssn,class_code);
alter table class add constraint clss_pk primary key(class_code);
alter table student_class add constraint st_fk foreign key (ssn) references student;
alter table student add constraint student_uk unique(lname,fname);
create index clss_desc_indx on class (class_description);

insert into student
values('409-56-7008', 'Bennet', 'Abraham',
'', '6223 Bateman St.', 'Berkeley', 'CA', '94705','26-feb-1988',10000);

insert into student
values ('213-46-8915', 'Green', 'Marjorie',
'', '309 63rd St. #411', 'Oakland', 'CA', '94618','25-feb-1989',20000 );

insert into student
values('238-95-7766', 'Gren', 'Cheryl',
'415 548-7723', '589 Darwin Ln.', 'Berkeley', 'CA', '94705',null,45000);

insert into student
values('998-72-3567', 'Greeenr', 'Albert',
'801 826-0752', '67 Seventh Av.', 'Salt Lake City', 'UT', '84152','24-feb-1992',15000);

insert into student
values('427-17-2319', 'Dull', 'Ann',
'415 836-7128', '3410 Blonde St.', 'Palo Alto', 'CA', '94301','23-feb-1993',30000);

insert into student
values('672-71-3249', 'Yokomoto', 'Akiko',
'415 935-4228', '3 Silver Ct.', 'Walnut Creek', 'CA', '94595','22-feb-1994',35000);

insert into student
values('267-41-2394', 'O''Leary', 'Michael',
'409-56-7008', '22 Cleveland Av. #14', 'San Jose', 'CA', '95128','12-feb-1995',32000);

insert into student
values('472-27-2349', 'Gringlesby', 'Burt',
'707 938-6445', 'PO Box 792', 'Covelo', 'NY', '95428','12-feb-1996',34000);

insert into student
values('527-72-3246', 'Greene', 'Morningstar',
'615 297-2723', '22 Graybar House Rd.', 'Nashville', 'TN', '37215','11-feb-1995',25000);

insert into student
values('999-00-0000', 'Al', 'Cal',
'615 297-2723', '22 Graybar House Rd.', 'Nashville', 'TN', '37215','06-feb-1998',22000);

insert into student
values('172-32-1176', 'White', 'Johnson',
'408 496-7223', '10932 Bigge Rd.', 'Menlo Park', 'ma', '94025','05-feb-1999',23000);

insert into student
values('712-45-1867', 'del Castillo', 'Innes',
'615 996-8275', '2286 Cram Pl. #86', 'Ann Arbor', 'MI', '48105','04-feb-1982',23500);

insert into student
values('846-92-7186', 'Hunter', 'Sheryl',
'415 836-7128', '3410 Blonde St.', 'Palo Alto', 'CA', '94301','03-feb-1979',18000);

insert into student
values('486-29-1786', 'Locksley', 'Chastity',
'415 585-4620', '18 Broadway Av.', 'San Francisco', 'CA', '94130','02-feb-1978',15500);

insert into student
values('648-92-1872', 'Blotchet-Halls', 'Reginald',
'503 745-6402', '55 Hillsdale Bl.', 'Corvallis', 'OR', '97330','01-feb-1977',43000);

insert into class
values('37','Database Programming');

insert into class
values('3','Introduction to Computers');

insert into class
values('32','Introduction to C programming');

insert into class
values('34','Intro to principles');

insert into class
values('14A','Operating systems');

insert into class
values('1','');

insert into class
values('55','');


insert into student_class
values('409-56-7008', '37');

insert into student_class
values ('213-46-8915', '32');


insert into student_class
values('998-72-3567', '3');

insert into student_class
values('998-72-3567', '55');

insert into student_class
values('427-17-2319', '34');

insert into student_class
values('672-71-3249', '3');

insert into student_class
values('267-41-2394', '34');

insert into student_class
values('472-27-2349', '32');

insert into student_class
values('527-72-3246', '1');

insert into student_class
values('172-32-1176', '37');

insert into student_class
values('712-45-1867', '37');

insert into student_class
values('846-92-7186', '32');

insert into student_class
values('486-29-1786', '1');

insert into student_class
values('648-92-1872', '55');

***************************************************************************************************

0 0
Add a comment Improve this question Transcribed image text
Answer #1

create table student(ssn char(11) not null,
                   lname varchar(40) not null,
                   fname varchar(20) not null,
                   phone char(12),
                   address varchar(40),
                   city varchar(20),
                   state char(2),
                   zip char(5),
                   dob date,
                   salary number);
                  
create table class(class_code varchar2(10),
                   class_description varchar2(30));

create table student_class(ssn char(11) not null,
                           class_code varchar2(10) not null);
                          
                          
alter table student add constraint student_pk primary key (ssn);

alter table student_class add constraint stu_cla_pk primary key(ssn,class_code);

alter table class add constraint clss_pk primary key(class_code);

alter table student_class add constraint st_fk foreign key (ssn) references student;

alter table student add constraint student_uk unique(lname,fname);

create index clss_desc_indx on class (class_description);


insert into student values('409-56-7008', 'Bennet', 'Abraham','', '6223 Bateman St.', 'Berkeley', 'CA', '94705','26-feb-1988',10000);
insert into student values ('213-46-8915', 'Green', 'Marjorie','', '309 63rd St. #411', 'Oakland', 'CA', '94618','25-feb-1989',20000 );
insert into student values('238-95-7766', 'Gren', 'Cheryl','415 548-7723', '589 Darwin Ln.', 'Berkeley', 'CA', '94705',null,45000);
insert into student values('998-72-3567', 'Greeenr', 'Albert','801 826-0752', '67 Seventh Av.', 'Salt Lake City', 'UT', '84152','24-feb-1992',15000);
insert into student values('427-17-2319', 'Dull', 'Ann','415 836-7128', '3410 Blonde St.', 'Palo Alto', 'CA', '94301','23-feb-1993',30000);
insert into student values('672-71-3249', 'Yokomoto', 'Akiko','415 935-4228', '3 Silver Ct.', 'Walnut Creek', 'CA', '94595','22-feb-1994',35000);
insert into student values('267-41-2394', 'O''Leary', 'Michael','409-56-7008', '22 Cleveland Av. #14', 'San Jose', 'CA', '95128','12-feb-1995',32000);
insert into student values('472-27-2349', 'Gringlesby', 'Burt','707 938-6445', 'PO Box 792', 'Covelo', 'NY', '95428','12-feb-1996',34000);
insert into student values('527-72-3246', 'Greene', 'Morningstar','615 297-2723', '22 Graybar House Rd.', 'Nashville', 'TN', '37215','11-feb-1995',25000);
insert into student values('999-00-0000', 'Al', 'Cal','615 297-2723', '22 Graybar House Rd.', 'Nashville', 'TN', '37215','06-feb-1998',22000);
insert into student values('172-32-1176', 'White', 'Johnson','408 496-7223', '10932 Bigge Rd.', 'Menlo Park', 'ma', '94025','05-feb-1999',23000);
insert into student values('712-45-1867', 'del Castillo', 'Innes','615 996-8275', '2286 Cram Pl. #86', 'Ann Arbor', 'MI', '48105','04-feb-1982',23500);
insert into student values('846-92-7186', 'Hunter', 'Sheryl','415 836-7128', '3410 Blonde St.', 'Palo Alto', 'CA', '94301','03-feb-1979',18000);
insert into student values('486-29-1786', 'Locksley', 'Chastity','415 585-4620', '18 Broadway Av.', 'San Francisco', 'CA', '94130','02-feb-1978',15500);
insert into student values('648-92-1872', 'Blotchet-Halls', 'Reginald','503 745-6402', '55 Hillsdale Bl.', 'Corvallis', 'OR', '97330','01-feb-1977',43000);

insert into class values('37','Database Programming');

insert into class values('3','Introduction to Computers');
insert into class values('32','Introduction to C programming');

insert into class values('34','Intro to principles');

insert into class values('14A','Operating systems');

insert into class values('1','');

insert into class values('55','');

insert into student_class values('409-56-7008', '37');

insert into student_class values ('213-46-8915', '32');

insert into student_class values('998-72-3567', '3');

insert into student_class values('998-72-3567', '55');

insert into student_class values('427-17-2319', '34');

insert into student_class values('672-71-3249', '3');

insert into student_class values('267-41-2394', '34');

insert into student_class values('472-27-2349', '32');

insert into student_class values('527-72-3246', '1');

insert into student_class values('172-32-1176', '37');

insert into student_class values('712-45-1867', '37');

insert into student_class values('846-92-7186', '32');

insert into student_class values('486-29-1786', '1');

insert into student_class values('648-92-1872', '55');


select * from student;
select * from class;
select * from student_class;

QUERIES

select ssn,class_code
from class,student
where (ssn,class_code) not in (select ssn,class_code from student_class);

select NVL(class_description,'No description available yet') class_description,lname,ssn,class_code
from class,student
where (ssn,class_code) not in (select ssn,class_code from student_class);

SQL select Fron student; LNAME SSH FNAME PHONE ADDRESS CITY ST ZIP DOB SALARY 89-56-7008 Bennet 213-46-8915 Green 238-95-7766

SQL> select From class; CLASS CODE CLASS DESCRIPTION 37 Database Progranming Introduction to Computers Introduction to C prog

SQL> select ssn,class_code 2 From class,student 3 where (ssn,class_code) not in (select ssn,class_code from student class); S

267-41-2394 32 409-56-7008 32 427-17-2319 32 48ό-29-178ό 32 527-72-3246 32 648-92-1872 32 672-71-3249 32 712-45-18ό7 32 998-7

SQL> select NUL (class_description, No description available yet class_description,1name,ssn,cla SQL> 2 From class,student 3

media%2Fcf5%2Fcf5bd2f7-5dc8-40e4-a490-12

media%2F678%2F6786ea49-5a5e-467a-981d-5b

Add a comment
Know the answer?
Add Answer to:
9 We want to find out the courses that each student is not enrolled in. Give a listing of the course descriptions, and the students (lname) who are not taking that specific course (Use a cartesi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT