In: Computer Science
DROP TABLE registration;
DROP TABLE sections;
DROP TABLE courses;
DROP TABLE students;
DROP TABLE instructors;
CREATE TABLE courses (
cid varchar2(9) NOT NULL,
cname varchar2(50) NOT NULL,
credits number(1) DEFAULT 3,
prereq varchar2(9),
CONSTRAINT pk_courses PRIMARY KEY (cid)
);
INSERT INTO courses VALUES ('IS 201','Java
Programming',3,null);
INSERT INTO courses VALUES ('IS 202','C++ Programming',3,'IS
201');
INSERT INTO courses VALUES ('IS 301','Web Design',3,null);
INSERT INTO courses VALUES ('IS 331','Business
Applications',3,null);
INSERT INTO courses VALUES ('IS 401','Database Design',3,'IS
331');
INSERT INTO courses VALUES ('IS 413','SQL Programming',3,'IS
401');
CREATE TABLE students (
sid char(9) NOT NULL,
lname varchar(30) NOT NULL ,
fname varchar2(30) NOT NULL ,
gender char(1) NOT NULL ,
addr varchar2(50) NOT NULL ,
city varchar2(20) NOT NULL ,
state char(2) NOT NULL ,
zip varchar2(10) NOT NULL ,
phone varchar2(14) NULL ,
birthdate date NULL ,
tuitionRate number(7, 2) NOT NULL ,
creditsEarned number(3) NOT NULL ,
CONSTRAINT pk_students PRIMARY KEY (sid)
);
INSERT INTO students VALUES ('100000001','Lee','George','M','15
Merchant
Street','Honolulu','HI','96818','808-524-3333','01-MAY-1965',5000.00,47);
INSERT INTO students VALUES
('100000002','Yamamoto','Bill','M','3432 Birch
Street','Honolulu','HI','96814','808-522-2212','03-JUN-1958',5000.00,12);
INSERT INTO students VALUES ('100000003','Carver','Hillary','F','22
Aardvark
Avenue','Washington','DC','10101','800-212-3246','23-AUG-1991',5000.00,69);
INSERT INTO students VALUES ('100000004','King','Linda','F','341
Kaapahu
Road','Paauilo','HI','96776',NULL,'01-SEP-1998',4399.00,6);
INSERT INTO students VALUES
('100000005','Rollings','Willie','M','1221 Ala Moana
Blvd','Honolulu','HI','96814',NULL,NULL,4888.00,0);
INSERT INTO students VALUES
('100000006','Alexander','Wanda','F','93-123 Old Mill
Road','Honokaa','HI','96727','808-776-2313','02-OCT-1997',5000.00,99);
INSERT INTO students VALUES ('100000007','Carver','Bill','M','33
Richards
Street','Honolulu','HI','96813',NULL,'22-OCT-1990',5000.00,0);
INSERT INTO students VALUES ('100000008','DeLuz','Bob','M','102
Orleans Ave','San
Francisco','CA','97745','808-555-3324','01-MAR-1998',5000.00,14);
INSERT INTO students VALUES ('100000009','Lee','Lisa','F','45 Fong
Avenue','San
Francisco','CA','97767','808-333-3432','21-APR-1997',5000.00,26);
INSERT INTO students VALUES ('100000010','Garcia','Sherrie','F','2
S.
Beretania','Honolulu','HI','96817','808-663-4453','03-DEC-1997',5000.00,29);
INSERT INTO students VALUES ('100000011','Kamaka','Oscar','M','34
Kapolani
Blvd','Honolulu','HI','96813','808-533-3332','12-FEB-1998',5000.00,0);
CREATE TABLE instructors (
inId char(9) NOT NULL,
iLname varchar2(30) NOT NULL,
iFname varchar2(30) NOT NULL,
rank varchar2(10) NOT NULL,
office varchar2(10) NULL,
phone varchar2(20) NULL,
salary number(8,2) DEFAULT 0,
CONSTRAINT pk_instructors PRIMARY KEY (inID)
);
INSERT INTO instructors VALUES
('200000001','Souza','Edward','Lecturer','LM101','808-533-4241',5000.00);
INSERT INTO instructors VALUES
('200000002','Tenzer','Laurie','Associate','LM102','808-533-4244',5000.00);
INSERT INTO instructors VALUES
('200000003','Otake','Bill','Assistant','MR101','808-533-4247',5800.00);
CREATE TABLE sections (
crn char(4) NOT NULL,
cid varchar2(9) NOT NULL,
section char DEFAULT 'A',
inId char(9) NOT NULL,
days varchar2(10) DEFAULT 'TBA',
time varchar2(16) DEFAULT 'TBA',
room varchar2(10) NULL,
CONSTRAINT pk_sections PRIMARY KEY (crn),
CONSTRAINT fk_inid_sections FOREIGN KEY (inid)
REFERENCES instructors(inid),
CONSTRAINT fk_cid_sections FOREIGN KEY (cid)
REFERENCES courses(cid)
);
INSERT INTO sections VALUES ('1000','IS
201','A','200000003','MWF','08:00 - 08:50','CL100');
INSERT INTO sections VALUES ('1001','IS
201','B','200000003','MWF','09:00 - 09:50','CL100');
INSERT INTO sections VALUES ('1002','IS
201','C','200000001','TTh','08:00 - 09:15','CL102');
INSERT INTO sections VALUES ('1003','IS
301','A','200000002','TTh','09:30 - 10:45','CL340');
INSERT INTO sections VALUES ('1004','IS
301','B','200000002','MWF','09:00 - 09:50','CL340');
INSERT INTO sections VALUES ('1005','IS
413','A','200000001','MWF','09:00 - 09:50','CL230');
CREATE TABLE registration (
crn char(4) NOT NULL,
sid char(9) NOT NULL,
CONSTRAINT pk_registration PRIMARY KEY
(crn,sid),
CONSTRAINT fk_crn_registration FOREIGN KEY (crn)
references sections(crn),
CONSTRAINT fk_sid_registration FOREIGN KEY (sid)
references students(sid)
);
INSERT INTO registration VALUES ('1000','100000001');
INSERT INTO registration VALUES ('1003','100000001');
INSERT INTO registration VALUES ('1005','100000001');
INSERT INTO registration VALUES ('1001','100000002');
INSERT INTO registration VALUES ('1004','100000002');
INSERT INTO registration VALUES ('1005','100000003');
INSERT INTO registration VALUES ('1002','100000004');
INSERT INTO registration VALUES ('1003','100000004');
INSERT INTO registration VALUES ('1005','100000004');
INSERT INTO registration VALUES ('1000','100000005');
INSERT INTO registration VALUES ('1003','100000005');
INSERT INTO registration VALUES ('1002','100000008');
INSERT INTO registration VALUES ('1004','100000008');
INSERT INTO registration VALUES ('1002','100000009');
INSERT INTO registration VALUES ('1005','100000009');
INSERT INTO registration VALUES ('1002','100000010');
INSERT INTO registration VALUES ('1005','100000010');
INSERT INTO registration VALUES ('1000','100000011');
INSERT INTO registration VALUES ('1003','100000011');
INSERT INTO registration VALUES ('1005','100000011');
commit;
for the ist query i think you have missed copying one table
There is no such data like department name, employee name, employee_ID
if you mean instructor as an employee i have written the query. If not upload the table again
query 3
SELECT courses.cid, courses.cname,sections.section, instructors.iLname, instructors.iFname,sections.days,sections.time, sections.room from sections join courses on sections.cid= courses.cid join instructors on sections.inid= instructors.inid
query 4
SELECT courses.cid, courses.cname,sections.section,students.sid, students.lname, students.fname ,registration.crn from registration join sections on registration.crn= sections.crn join courses on sections.cid= courses.cid join students on registration.sid = students.sid where registration.crn ='1003' order by students.lname, students.fname asc
query 1
SELECT inid,iLname, iFname, office from instructors order by office asc
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
please find the attachment for the output