Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

questions dbms

The document outlines various SQL queries and database operations related to a student enrollment system, including retrieving course titles, student IDs, instructor salaries, and calculating GPAs and CGPAs. It also includes the creation of tables for students, courses, and enrollments with specific constraints and triggers. Additionally, it discusses data manipulation tasks such as increasing salaries, deleting courses, and inserting student records.

Uploaded by

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

questions dbms

The document outlines various SQL queries and database operations related to a student enrollment system, including retrieving course titles, student IDs, instructor salaries, and calculating GPAs and CGPAs. It also includes the creation of tables for students, courses, and enrollments with specific constraints and triggers. Additionally, it discusses data manipulation tasks such as increasing salaries, deleting courses, and inserting student records.

Uploaded by

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

Practical 3, 4, 5:

Questions)

1) find titles of courses in the cs department name that have 3 credits


2) find the ids of all students who are taught by an instructor named
3) find the highest salary of any instructor
4) find all intsructors earning the highest salary

A =4
A- = 3.7
B+ = 3.3
B =3
suppose u are given an relation gradepoint (grade, points)- grade primary key THE GRADE
POINTS EARNED BY student on course : a grade point earned by a student for a course is
defined by credit of the course multiplied by grade point grade= credit*gp
● Find total gp earned by the student student id… across all courses taken by him ,
● find the cgpa of student= total grade points % total credit,
● Find the ids and cgpa of each student

1) select title
-> from course
-> where dept_name = 'Physics'
-> and credits =3;
2)SELECT DISTINCT students.ID
FROM students
JOIN takes USING(ID)
JOIN instructor JOIN teaches USING(ID)
USING(course_id, sec_id, semester, year)
WHERE instructor.name = 'Amit Sharma';

3) select max(salary) from instructor

4) select ID, name from instructor where salary = (select max(salary) from instructor)
1) select * from students;
2) gp=
1)
SELECT SUM(credits * points)
-> FROM (takes NATURAL JOIN course) NATURAL JOIN grade_points
-> WHERE ID = 'S003';

SELECT SUM(c.credits*g.points)
-> FROM takes AS t
-> INNER JOIN course AS c ON t.course_id= c.course_id
-> INNER JOIN grade_points AS g ON t.grade = g.grade
-> WHERE t.ID ='S003';
2)SELECT SUM(credits * points) / SUM(credits) AS GPA
-> FROM (takes NATURAL JOIN course) NATURAL JOIN grade_points
-> WHERE ID = 'S003';

3)SELECT s.ID,
CASE
WHEN SUM(c.credits) = 0 THEN 0
ELSE SUM(g.points * c.credits) / SUM(c.credits)
END AS cgpa
FROM students s
LEFT JOIN takes t ON s.ID = t.ID
LEFT JOIN grade_points g ON t.grade = g.grade
LEFT JOIN course c ON t.course_id = c.course_id
GROUP BY s.ID;
LAB) SELECT ORDER BY GRADE or group by grade

INCREASE THE SA;LARY OF ALL INSTRUCTORS IN COMP SCIENCE DEPTARTMENT BY


10 PERCENT DOUBLE THE SALARY WHOS NAME IS ABHISHEK
4 B) Delete all courses that never have been offer
4 c) insert every student whos pt are ,more than 100 credits

1.Increase the salary of all instructors in computer science department by 10%


2. delete all courses that have never been offer
3. students whose credit points are more than 100 will get internship in the same department in
which the student and instructor is with stipend 10,000

DELETE FROM course


WHERE course_id NOT IN (SELECT DISTINCT course_id FROM takes);

SELECT s.ID,
-> CASE
-> WHEN SUM(g.points * c.credits) IS NULL THEN 0
-> ELSE SUM(g.points * c.credits) / SUM(c.credits)
-> END AS cgpa
-> FROM students s
-> LEFT JOIN takes t ON s.ID = t.ID
-> LEFT JOIN gradepoints g ON t.grade = g.grade
-> LEFT JOIN course c ON t.course_id = c.course_id
-> GROUP BY s.ID;

3)
4 a)
● Find the id and name of each student who has taken atleast one computer science
course.(distinct)

SELECT s.ID, s.name

FROM students s

LEFT JOIN takes t ON s.ID = t.ID AND t.year = 2024

WHERE t.ID IS NULL;


● Find the ids and name of each student who has not taken any course in 2024
SELECT s.ID, s.name
FROM students s
LEFT JOIN takes t ON s.ID = t.ID AND t.year = 2024
WHERE t.ID IS NULL;

● For each department find the maximum salary of instructor


SELECT dept_name, MAX(salary) AS max_salary
FROM instructor

GROUP BY dept_name;

● Find the lowest maximum salary per department(one query)

SELECT MIN(max_salary) AS lowest_max_salary


FROM (
SELECT MAX(salary) AS max_salary
FROM instructor
GROUP BY dept_name
) AS dept_max_salaries;
SELECT dept_name, MAX(salary) AS max_salary
FROM instructor
GROUP BY dept_name
HAVING MAX(salary) = (
SELECT MIN(max_salary)
FROM (
SELECT MAX(salary) AS max_salary
FROM instructor
GROUP BY dept_name
) AS dept_max_salaries
);
Practical 6:
Create the following tables for student enrolment system

1)students(student_id(primary),name,dob,email)

2) course (course_id(primary),course_name,credits=[1,5])

3)enrolment(enrolment_id(primary),student_id,course_id,grade={A,B,C,D,F})

Design these tables using suitable datatype and constraints

Dob must not be future date

Email should contain @

create table students(

student_id INT PRIMARY KEY,

name VARCHAR(50),

date_of_birth DATE,

email VARCHAR(100) UNIQUE CHECK (email LIKE '%_@__%.__%')

);

DELIMITER $$

CREATE TRIGGER check_date_of_birth


BEFORE INSERT ON students

FOR EACH ROW

BEGIN

IF NEW.date_of_birth > CURDATE() THEN

SIGNAL SQLSTATE '45000'

SET MESSAGE_TEXT = 'Date of birth cannot be in future.';

END IF;

END $$

DELIMITER ;

CREATE TABLE courses(

course_id INT PRIMARY KEY,

course_name VARCHAR(50),

credits numeric(2,1),

CHECK(credits BETWEEN 1 AND 5)

);

CREATE TABLE enrollments(

enrollment_id INT PRIMARY KEY,

student_id INT,

course_id INT,

grade CHAR(1),

FOREIGN KEY(student_id) REFERENCES students(student_id) ON DELETE CASCADE,


FOREIGN KEY(course_id) REFERENCES courses(course_id),

CHECK(grade IN ('A','B', 'C', 'D', 'F'))

);

INSERT INTO students VALUES (1, 'Alice', '2000-03-21', 'alice@ab.com');

INSERT INTO students VALUES (2, 'bob', '2001-03-24', 'bob@ab.com');

INSERT INTO courses VALUES (101,'Databse systems', 3);

INSERT INTO courses VALUES (102,'Operating Systems', 4);

INSERT INTO enrollments VALUES (1,1,101,'A');

INSERT INTO enrollments VALUES (2,2,102, 'B');

INSERT INTO students VALUES (3, 'CHARLIE', '2001-07-15', 'ALICE@example.com');

INSERT INTO students VALUES (3, 'CHARLIE', '2001-07-15', 'charlie_at_example.com');

INSERT INTO students VALUES (4, 'EVE', '2025-01-01', 'EVE@example.com');

INSERT INTO courses VALUES (103,'Networks', 6);

INSERT INTO enrollments VALUES (3,99,101,'A');


Practical 7:
Transforming ERD into relational schema diagram

You might also like