0% found this document useful (0 votes)
6 views

ASSIGNMENT_5_DBMS_LAB[5]

The document contains SQL commands for creating tables related to students, colleges, and applications in a Database Management System lab assignment. It includes data insertion for students and colleges, as well as various SQL queries to retrieve specific information about student applications. The queries address different scenarios, such as finding students who applied to colleges in California, those with high CGPA applying to Stanford, and identifying colleges with no applications.

Uploaded by

paneer027
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

ASSIGNMENT_5_DBMS_LAB[5]

The document contains SQL commands for creating tables related to students, colleges, and applications in a Database Management System lab assignment. It includes data insertion for students and colleges, as well as various SQL queries to retrieve specific information about student applications. The queries address different scenarios, such as finding students who applied to colleges in California, those with high CGPA applying to Stanford, and identifying colleges with no applications.

Uploaded by

paneer027
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

ANUJ RAJPUT (BCA) SEC H

CLASS ROLL NO - 8

2442010084

SUBJECT NAME - DATABASE MANAGEMENT SYSTEM LAB(BCAC 0816)

ASSIGNMENT 5_________________________________

CREATE TABLE Student ( sID INT PRIMARY KEY, sName VARCHAR2(10), CGPA NUMBER(2,1),

marks INT, DoB DATE

CREATE TABLE College (

cName VARCHAR2(10) PRIMARY KEY, cState VARCHAR2(10),

enrollment INT

CREATE TABLE Apply ( sID INT,

cName VARCHAR2(10), major VARCHAR2(20),

decision CHAR(1),

FOREIGN KEY (sID) REFERENCES Student(sID),

FOREIGN KEY (cName) REFERENCES College(cName)

College

INSERT INTO College (cName, cState, enrollment) VALUES ('Stanford', 'CA', 15000); INSERT INTO College
(cName, cState, enrollment) VALUES ('Berkeley', 'CA', 36000); INSERT INTO College (cName, cState,
enrollment) VALUES ('MIT', 'MA', 10000); INSERT INTO College (cName, cState, enrollment) VALUES
('Cornell', 'NY', 21000); INSERT INTO College (cName, cState, enrollment) VALUES ('Harvard', 'MA',
50040);
Student

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (123, 'Amit', 3.9, 1000, TO_DATE('26-
JUN-1996', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (234, 'Balbir', 3.6, 1500, TO_DATE('07-
APR-1995', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (345, 'chirag', 3.5, 500, TO_DATE('04-FEB-
1995', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (456, 'Dev', 3.9, 1000, TO_DATE('24-JUL-
1997', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (567, 'Eshan', 2.9, 2000, TO_DATE('21-
DEC-1996', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (678, 'Faizal', 3.8, 200, TO_DATE('27-
AUG-1996', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (789, 'Garvit', 3.4, 800, TO_DATE('08-
OCT-1996', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (987, 'Himani', 3.7, 800, TO_DATE('27-
MAR-1997', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (876, 'Ishan', 3.9, 400, TO_DATE('07-
MAR-1996', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (765, 'Jay', 2.9, 1500, TO_DATE('08-AUG-
1998', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (654, 'Amit', 3.9, 1000, TO_DATE('26-
MAY-1996', 'DD-MON-YYYY'));

INSERT INTO Student (sID, sName, CGPA, marks, DoB) VALUES (543, 'chirag', 3.4, 2000, TO_DATE('27-
AUG-1998', 'DD-MON-YYYY'));

Apply

INSERT INTO Apply (sID, cName, major, decision) VALUES (123, 'Stanford', 'CS', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (123, 'Stanford', 'EE', 'N');
INSERT INTO Apply (sID, cName, major, decision) VALUES (123, 'Berkeley', 'CS', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (123, 'Cornell', 'EE', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (234, 'Berkeley', 'biology', 'N');

INSERT INTO Apply (sID, cName, major, decision) VALUES (345, 'MIT', 'bioengineering', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (345, 'Cornell', 'bioengineering', 'N');

INSERT INTO Apply (sID, cName, major, decision) VALUES (345, 'Cornell', 'CS', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (345, 'Cornell', 'EE', 'N');

INSERT INTO Apply (sID, cName, major, decision) VALUES (678, 'Stanford', 'history', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (987, 'Stanford', 'CS', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (987, 'Berkeley', 'CS', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (876, 'Stanford', 'CS', 'N');

INSERT INTO Apply (sID, cName, major, decision) VALUES (876, 'MIT', 'biology', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (876, 'MIT', 'marine biology', 'N');

INSERT INTO Apply (sID, cName, major, decision) VALUES (765, 'Stanford', 'history', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (765, 'Cornell', 'history', 'N');

INSERT INTO Apply (sID, cName, major, decision) VALUES (765, 'Cornell', 'psychology', 'Y');

INSERT INTO Apply (sID, cName, major, decision) VALUES (543, 'MIT', 'CS', 'N');

QUESTIONS::::

QUESTION 1: Produce a combine table in which each student is combine with every other application.

SOLUTION:

Command- SELECT * FROM Student CROSS JOIN Apply;


QUESTION 2. Give Student ID, name, CGPA and name of college and major each student applied to.

SOLUTION:

Command- SELECT Student.sID, Student.sName, Student.CGPA, Apply.cName, Apply.major FROM


Student

INNER JOIN Apply ON Student.sID = Apply.sID;

QUESTION 3. Find detail of applications who applied to California State.

SOLUTION:
Command- SELECT Apply.*
FROM Apply

JOIN College ON Apply.cName = College.cName WHERE College.cState = 'CA';

QUESTION 4. IDs, name, CGPA of students and name of college with CGPA > 3.7 applying to Stanford

SOLUTION:

Command- SELECT Student.sID, Student.sName, Student.CGPA, Apply.cName FROM Student

JOIN Apply ON Student.sID = Apply.sID

WHERE Student.CGPA > 3.7 AND Apply.cName = 'Stanford';


QUESTION 5. Find detail of student and application who applied to colleges at New York

SOLUTION:

Command- SELECT Student.*, Apply.* FROM Student

JOIN Apply ON Student.sID = Apply.sID

JOIN College ON Apply.cName = College.cName WHERE College.cState = 'NY';

QUESTION 6. Find detail of student who have not applied to any of college

SOLUTION:

Command- SELECT * FROM Student

WHERE sID NOT IN (SELECT sID FROM Apply);


QUESTION 7. Find college where no student have applied

SOLUTION:

Command- SELECT * FROM College

WHERE cName NOT IN (SELECT DISTINCT cName FROM Apply);

QUESTION 8. Find sID who have only one application

SOLUTION:

Command- SELECT sID FROM Apply

GROUP BY sID

HAVING COUNT(*) = 1;
QUESTION 9. Find name and CGPA of applicants who apply to any college whose enrollment is not
more than 25000.

SOLUTION:

Command- SELECT Student.sName, Student.CGPA FROM Student

JOIN Apply ON Student.sID = Apply.sID

JOIN College ON Apply.cName = College.cName WHERE College.enrollment <= 25000;

You might also like