0% found this document useful (0 votes)
19 views8 pages

Subhasis Das Ass-3

Uploaded by

Ben Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views8 pages

Subhasis Das Ass-3

Uploaded by

Ben Johnson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ASSIGNMENT – 3

SUBJECT - DBMS
NAME – Subhasis Das ROLL NO – 302011001107
Year – 2ND Semester - 3rd
DEPARTMENT – INFORMATION AND TECHNOLOGY
________________________________________________________
ER DIAGRAM:

SCHEMA:
CREATE DATABASE INSTITUTION;

USE INSTITUTION;

CREATE TABLE COURSE(


-> COURSE_ID INT NOT NULL PRIMARY KEY,
-> COURSE_NAME VARCHAR(20),
-> MXIN INT(2) NOT NULL);

CREATE TABLE ENROLLMENT(


-> STUID INT(5) NOT NULL PRIMARY KEY,
-> STUNAME VARCHAR(15),
-> COURSE_ID INT NOT NULL,
-> NOS INT(1) NOT NULL,
-> FOREIGN KEY (COURSE_ID) REFERENCES COURSE(COURSE_ID),
-> CHECK (NOS>=5 AND NOS<=6));

CREATE TABLE SUBJECT(


-> COURSE_ID INT NOT NULL,
-> SUBNAME VARCHAR(20) NOT NULL,
-> FOREIGN KEY (COURSE_ID) REFERENCES COURSE(COURSE_ID));

CREATE TABLE RESULTS(


-> STUID INT(5) NOT NULL,
-> COURSE_ID INT NOT NULL,
-> SUBNAME VARCHAR(20) NOT NULL,
-> MGRADE VARCHAR(2),
-> FOREIGN KEY (STUID) REFERENCES ENROLLMENT(STUID),
-> FOREIGN KEY (COURSE_ID) REFERENCES COURSE(COURSE_ID));

1. Insert at least five tuples in each table.


INSERT INTO COURSE VALUES
-> (10, 'CSE', 35),
-> (20, 'IT', 40),
-> (30, 'ETCE', 45),
-> (40, 'EE', 50),
-> (50, 'IEE', 55);

INSERT INTO ENROLLMENT VALUES


-> (18065, 'SOHOM', 10, 5),
-> (18066, 'SANGITA', 20, 5),
-> (18068, 'WASIM', 40, 6),
-> (18067, 'SUBHASIS', 30, 5),
-> (18069, 'RIMA', 20, 5);

INSERT INTO SUBJECT VALUES


-> (10, '0S'),
-> (10, 'OOP'),
-> (10, 'DBSM'),
-> (10, 'DSA'),
-> (10, 'MATHS');
INSERT INTO SUBJECT VALUES
-> (20, 'CKT DSIGN'),
-> (20, 'ELECT STATS'),
-> (20, 'TELECOMM'),
-> (20, 'MATHS'),
-> (20, 'DIGITAL');

INSERT INTO SUBJECT VALUES


-> (30, 'DSA'),
-> (30, 'COA'),
-> (30, 'OOP'),
-> (30, 'SECURITY'),
-> (30, 'DBMS');

INSERT INTO SUBJECT VALUES


-> (40, 'TDM'),
-> (40, 'SURVEY'),
-> (40, 'STUCT'),
-> (40, 'GEO'),
-> (40, 'DRG');

INSERT INTO SUBJECT VALUES


-> (50, 'EGM'),
-> (50, 'EST'),
-> (50, 'INS'),
-> (50, 'TRM'),
-> (50, 'DGL');

INSERT INTO RESULTS VALUES


-> (18069, 20, 'CKT DESIGN', 'A'),
-> (18069, 20, 'TELECOMM', 'A'),
-> (18069, 20, 'MATHS', 'B'),
-> (18069, 20, 'ELEC STATS', 'A'),
-> (18069, 20, 'DIGITAL', 'B+');

INSERT INTO RESULTS VALUES


-> (18065, 10, 'OS', 'A-'),
-> (18065, 10, 'OOP', 'B'),
-> (18065, 10, 'DBSM', 'B+'),
-> (18065, 10, 'DSA', 'A'),
-> (18065, 10, 'MATHS', 'B');

INSERT INTO RESULTS VALUES


-> (18066, 20, 'ELEC STATS', 'A'),
-> (18066, 20, 'DIGITAL', 'A-'),
-> (18066, 20, 'CKT DESIGN', 'B+'),
-> (18066, 20, 'TELECOMM', 'B'),
-> (18066, 20, 'MATHS', 'A');

INSERT INTO RESULTS VALUES


-> (18067, 30, 'DSA', 'A'),
-> (18067, 30, 'COA', 'A-'),
-> (18067, 30, 'OOP', 'B+'),
-> (18067, 30, 'SECURITY', 'B'),
-> (18067, 30, 'DBMS', 'A');

INSERT INTO RESULTS VALUES


-> (18068, 40, 'TDM', 'A'),
-> (18068, 40, 'SURVEY', 'A-'),
-> (18068, 40, 'STUCT', 'B+'),
-> (18068, 40, 'GEO', 'B'),
-> (18068, 40, 'DRG', 'A-');

2. At the time of creation if we forget to create a field enrollment


date (ENROLL_DATE) in ENROLL table so add the field.
ALTER TABLE ENROLLMENT ADD ENROLL_DATE DATE;

3. Course name cannot be blank, therefore add the criteria in the


specific table.
ALTER TABLE COURSE MODIFY COURSE_NAME VARCHAR (20) NOT NULL;

4. Find the Course which has more than 3 students.


SELECT * FROM ENROLLMENT
-> WHERE COURSE_ID IN
-> (SELECT COURSE_ID FROM ENROLLMENT GROUP BY COURSE_ID HAVING
COUNT(*)>=3);

5. Give the details of a STUDENT with all Subjects and Grade where
he/she enroll (Enter the sid value as input).
SELECT E.STUID AS ID, E.STUNAME AS NAME, E.COURSE_ID AS COURSE_ID,
C.COURSE_NAME AS COURSE_NAME, R.SUBNAME AS SUBJECT_NAME,
R.MGRADE AS GRADE
-> FROM ENROLLMENT E, RESULTS R, COURSE C
-> WHERE E.STUID = R.STUID AND E.STUID=18067 AND
E.COURSE_ID=C.COURSE_ID;

6. Display the course where the maximum number of students


enrolls.

7. Find out the course where no student is enrolled.


SELECT COURSE_NAME FROM COURSE
-> WHERE COURSE_ID NOT IN (SELECT COURSE_ID FROM ENROLLMENT
GROUP BY COURSE_ID);

8. Delete Course no 30 from COURSE table.


DELETE FROM COURSE WHERE CID = 30 ;

9. Rename the COURSE table as DEPARTMENT.


ALTER TABLE COURSE RENAME TO DEPARTMENT;
10. Change the Marks Grade of Student “A” to “B” who is Enroll in
the subject DBMS.
UPDATE RESULTS SET MGRADE ='B' WHERE SUBNAME = 'DBMS';

11. Delete the record of the student who is enrolled in the course
‘IT’.
DELETE FROM DEPARTMENT WHERE CNAME='IT';

12. Change the enroll date to ‘16-08-2018’ whose student id is


18069 (first convert the date into the default format).
UPDATE ENROLLMENT SET ENROLL_DATE ='2018-08-16';

You might also like