Consider the following relational database:
Student (stid, stName, stProg, Phone)
Programme (progId, prName, prDuration, prFee)
Course (courseCode, courseName, courseCredit)
CourseProgramme(progID, courseCode)
The underlined attributes form the primary key of the relations. In relation Student, the stProg is
the programme code of the student and should reference progId of the Programme table. Please
note that a course may be part of several programmes. Please note that the CourseProgramme relation has two foreign keys. Write and run the following SQL queries on the tables:
(i) Create the tables with the primary and foreign key constraints.
(ii) Insert at least 5 records in the first 3 tables and 20 records in the 4th table.
(iii) List all the Programmes of the University in the order of programme name
(iv) Find the list of all the courses of programme whose ID is “PGDCA”.
(v) Find the list of those courses that are part of more than one programme.
(vi) Find the list of courses, which are to be studied by a student whose ID is “S001”
(vii) Find the total credits of each programme.
(viii) Find the list of students in each Programme.
(ix) List the pair of students who share the same phone number.
(x) List all the students whose name starts with the alphabet ‘A’.
(i) Create the tables with the primary and foreign key constraints:
CREATE TABLE Student ( stid VARCHAR(10), stName VARCHAR(50), stProg VARCHAR(10), Phone VARCHAR(15), PRIMARY KEY (stid), FOREIGN KEY (stProg) REFERENCES Programme(progId) ); CREATE TABLE Programme ( progId VARCHAR(10), prName VARCHAR(50), prDuration INT, prFee DECIMAL(10,2), PRIMARY KEY (progId) ); CREATE TABLE Course ( courseCode VARCHAR(10), courseName VARCHAR(50), courseCredit INT, PRIMARY KEY (courseCode) ); CREATE TABLE CourseProgramme ( progId VARCHAR(10), courseCode VARCHAR(10), FOREIGN KEY (progId) REFERENCES Programme(progId), FOREIGN KEY (courseCode) REFERENCES Course(courseCode), PRIMARY KEY (progId, courseCode) );
(ii) Insert at least 5 records in the first 3 tables and 20 records __________ ___ ______ _______ ___ ____.
_____ ________ ______ _________ ___ ________ _______ ______ _____ _______ _________ ______.
____ _______ _______ ________ __________ _________ __________ ___.
____ ____ ______ _________ ____ ______ _______ _________ _________.
_________ __________ ______ ________ _______.
____ ___ _________ _____ ____.
__________ _______ _________ ____ __________.
____ __________ _____ _____ ___ ________ ___ ___ _____ ________.
_____ _________ ______ ___ __________ ________ _______ _____ _________ ______.
______ ________ ____ ____ ________ ______ ___ ________ __________ ________ __________.
___ ______ __________ ________ _____ __________ ________.
________ ______ ________ ________ ____ _____ __________ _____ ___ _______ _____ _____.
___ __________ ____ _______ _________ ______ ______ _______ ___ ________ ____ _________.
_____ _____ ___ ______ _________ _________.
_____ _______ __________ _________ __________ ______.
_____ ___ _______ __________ _____ _______ ______.
___ __________ _________ ___ ___ _____ ______ _______ _____.
________ __________ _________ ___ _______ ________ __________ ___ __________ __________ ____.
___ _____ __________ ___ _________.
_______ ___ _____ _______ ___ _______ ______ ________ __________ _________ _________.
_____ ______ ___ ______ ___.
_____ __________ ______ ______ ________ ______ ___.
______ __________ __________ ______ _________ ________ _______ _____.
________ ______ ______ _____ __________ ____ _______ ___ ___ _________.
______ ____ ____ __________ ___ _____ ______ ___ _________ _____ __________ _________.
________ _______ ______ ___ ____ ____ _________ ________ _____ ______ __________.
______ ______ _________ _____ ____ _________ _________ __________.
_______ __________ _________ _________ ____ _____.
_____ _________ ___ _________ ____.
____ _________ _________ _____ _____ ___ _________ _____.
___ _________ _______ __________ ______ __________.
___ ________ _______ ________ ___ ______ _______ _________ ___ _________ _____ ______.
_____ ________ _______ __________ _______ __________.
____ ______ _______ _____ _________.
____ ___ _______ ___ ______ ____ _____ ____ _____.
__________ _______ ____ _____ ________ _________ ___ _________ _______ ________ ______ ____.
__________ __________ __________ _____ __________.
_________ ________ ____ ________ ____ ______ ______ _______.
__________ ____ ________ __________ ________ ____ _____ ________ __________.
_______ _________ ________ ___ ________ _______ _______.
____ _________ ________ _____ ___ ____ ______ _____ __________ ___ _____.
____ _________ __________ ____ _________ _______ ______ __________.
______ ______ __________ _________ ____.
__________ _________ __________ ______ _______ _________ __________ ________ ______ _________ ___.
_____ __________ _______ __________ __________ __________.
___ _______ ________ __________ _______ _______ ______ ____.
________ _______ _____ ____ __________ ______ ________ _______.
___ ____ _____ _______ __________ ___ _______ __________ ___ ____.
____ ________ _____ ________ _______ _______ _________.
__________ ___ ________ ___ _____.
____ _________ ________ ____ ___ _______.
______ _________ _______ _____ _________ _______ ________.
________ ____.
Get Full Answer on WhatsApp