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 in the 4th table:
-- Insert records into Student table INSERT INTO Student (stid, stName, stProg, Phone) VALUES ('S001', 'John Doe', 'PGDCA', '123-456-7890'), ('S002', 'Jane Smith', 'MCA', '987-654-3210'), ('S003', 'Alice Johnson', 'BCA', '111-222-3333'), ('S004', 'Bob Williams', 'PGDCA', '444-555-6666'), ('S005', 'Emily Brown', 'MCA', '777-888-9999'); -- Insert records into Programme table INSERT INTO Programme (progId, prName, prDuration, prFee) VALUES ('PGDCA', 'Post Graduate Diploma _________ _________ ___ _______ _________ _______ ________ ___ ________.
___ _________ ______ ___ _______ _______ ______ _________ ___.
_________ ____ ________ _____ ______ ___ ___ _____.
______ __________ _________ ___ ______ ______ __________ _____ _____ _______.
___ ___ __________ ______ ________ ______ ____ ________.
_____ ____ ______ ______ _________ _________ ____.
_________ __________ ______ ___ _______ ____ _________ ________.
_____ _______ ________ ____ ___ ______ _____.
___ ___ _____ _________ ____ ______ __________ ______ ___ ____ ________.
______ _______ _________ ________ _____ __________.
_____ _______ ___ ________ ______ _____ ___ ____.
______ ________ __________ ______ _________ _______ _____ _______ ______.
___ _______ ______ ___ ______ ___ _____ ________ ___ ________.
_____ _______ _____ _________ ________ ______ _________ ____.
__________ _____ ________ __________ ________.
__________ _______ ______ _________ __________ ___ ______.
______ ______ _____ __________ ________ _______ ____ ___ ____ _________ _____ ________.
_____ ___ _______ _______ ________ ______ ______ _____ _________ ______ ______.
_________ ________ _________ ________ ___ _________ _________ ___.
___ _________ ____ _____ _________ _____.
____ ______ ________ ____ _______ _______ ________ ________ ______ ____ _________.
________ _______ ______ ___ ______ _______ __________ _______.
________ ______ __________ _________ _____ _____.
_____ ______ _____ _____ _________ ______.
_______ ___ ___ __________ ________ _______ __________ _________ __________ _________.
__________ _______ _________ ______ _______.
_________ ______ ____ _________ _____ ____ __________ ______ ____ ___.
__________ __________ ______ _____ _______ ________ ______ _______ ____ __________ ________.
__________ ______ ______ _____ _____ ______ _____.
_______ __________ ________ ________ ________ _____ ___.
________ _____ ________ _______ _______ ____ ________ _____.
_______ __________ _________ ___ ________ ____ ________ _______ ____ _______ ___.
__________ _____ ___ _________ ______ ________ ___ ___ _________.
________ __________ _________ _________ _________ ___ _____ ________ __________ _________ _______.
___ _________ ____ ______ ___ _____ ______ _________ _____ ____ __________.
____ ______ _______ ______ _______ __________ _______.
_________ ______ _____ _____ ______ _________ ______ __________ ___ _____ _______ ___.
________ ____ ____ _________ ________ ________ ________ _____ ________ ____ ______.
______ _________ _____ ________ ________.
______ _____ _____ _______ _________ ________ __________.
___ _________ _____ __________ ___ _______ _____ _______ ___ _______ _________ __________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required