Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Tutorial 6

1. Write a database description for each of the relations shown, using SQL DDL (shorten,
abbreviate, or change any data names, as needed for your SQL version). Assume the
following attribute data types:
StudentID (integer, primary key), StudentName (25 characters), FacultyID (integer,
primary key), FacultyName (25 characters), CourseID (8 characters, primary key),
CourseName (15 characters), DateQualified (date), SectionNo (integer, primary key),
Semester (7 characters)

FROM Question >=2, use table above to write SQL Query, Faculty has the same meaning as
Instructor.
2. Create an SQL VIEW for following table

3. Write SQL data definition commands for each of the following queries:

a. How would you add an attribute, Class, to the Student table?

b. How would you remove the Registration table?


c. How would you change the FacultyName field from 25 characters to 40 characters?

4. Write SQL commands for the following:

a. Create two different forms of the INSERT command to add a student with a student
ID of 65798 and last name Lopez to the Student table.
 INSERT INTO `student` VALUES('65789','Lopez');
 INSERT INTO `student` (`studentID`,`studentName`)VALUES ('65788'
,'Lopez’);

b. Now write a command that will remove Lopez from the Student table.
 DELETE FROM student WHERE studentName='Lopez';

c. Create an SQL command that will modify the name of course ISM 4212 from
Database to Introduction to Relational Databases.
 UPDATE course SET CourseName='Relational
Databases' WHERE CourseID='ISM 4212';

5. Write SQL queries to answer the following questions:

a. Which students have an ID number that is less than 50000?


 SELECT * FROM `student` WHERE StudentID <50000;

b. What is the name of the faculty member whose ID is 4756?


 SELECT `FacultyName` FROM `faculty` WHERE `facultyID`='4756';

c. What is the smallest section number used in the first semester of 2008?
 SELECT MIN(`SectionNo`) FROM `section` WHERE Semester = 'I-
2008';

6. Write SQL queries to answer the following questions:

a. How many students are enrolled in Section 2714 in the first semester of 2008?
 SELECT COUNT(`studentID`) FROM `registration` WHERE `SectionNo`= 
'2714'

b. Which faculty members have qualified to teach a course since 1993? List the
faculty ID, courseID, and date of qualification.
 SELECT F.FacultyID, C.CourseID, Q.DateQualified FROM `faculty` 
AS F, `course` AS C, `qualified` AS Q WHERE YEAR(Q.DateQualifie
d) >= '1993' AND C.CourseID=Q.CourseID;

7. Write SQL queries to answer the following questions:


a. Which studentsID are enrolled in Database and Networking? (Hint: Use SectionNo
for each class so you can determine the answer from the Registration table by
itself.)
select * from student
 inner join registration on student.studentid = registration.studentid 
inner join section on registration.sectionno = section.sectionno 
inner join course on section.courseid = course.courseid 
where coursename ='Database' or coursename = 'networking';

b. Which instructors teach both Syst Analysis and Syst Design?


select FacultyName from faculty
inner join qualified ON faculty.facultyid = qualified.facultyid
inner join course on course.courseid = qualified.courseid
where coursename = 'System analysis'

8. Write SQL queries to answer the following questions:

a. What are the courses included in the Section table? List each course only once.
SELECT DISTINCT courseid FROM `section`;

b. List all students in alphabetical order by StudentName.


select * from student order by studentname DESC
select * from student order by studentname

c. List the students who are enrolled in each course in Semester I, 2008. Group the
students by the sections in which they are enroll

SELECT SECTION_NO,SEMESTER,STUDENT_ID FROM REGISTRATION WHERE SEMESTER = 'I-2008'


ORDER BY SECTION_NO, SEMESTER, STUDENT_ID;

You might also like