Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views23 pages

Dbms Practice Questions

Uploaded by

susmitapoli2004
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)
8 views23 pages

Dbms Practice Questions

Uploaded by

susmitapoli2004
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/ 23

PRACTICE QUESTION

1. What does the following query return?

SELECT COUNT (*) FROM Employee;


1. Total salary of employees
2. Number of employee records
3. Highest salary in Employee table
4. Sum of employee IDs

2. Which keyword is used to remove duplicate values in the result set?


1. UNIQUE
2. REMOVE
3. DISTINCT
4. NO DUPLICATE
3. What is the purpose of the GROUP BY clause in?
1. To delete data from groups
2. To combine rows with the same values
3. To restrict columns
4. To display foreign keys

4. Which of the following is a valid aggregate function?


1. UPDATE()
2. SUM()
3. DELETE()
4. SET()

5. What does this command do?

SELECT name FROM Students WHERE marks > 90;


1. Select names of students with marks less than 90
2. Select all students with exactly 90 marks
3. Select students who scored more than 90
4. Returns all students regardless of marks

6. The HAVING clause is used with:


1. WHERE clause
2. SELECT clause
3. GROUP BY clause
4. ORDER BY clause
7. Which of the following queries will retrieve names starting with 'A'?

SELECT name FROM emp WHERE name LIKE 'A%';


1. Correct
2. Incorrect syntax
3. It fetches names ending with 'A'
4. Only returns exact matches

8. Which of the following clauses restricts the rows returned by a query?


1. SELECT
2. FROM
3. WHERE
4. ORDER BY

9. What will this query return?

SELECT MAX(salary) FROM Employees;


1. Sum of all salaries
2. Maximum salary
3. Number of salaries
4. Employee ID

10. Which function gives the number of non-NULL values?


1. SUM
2. MAX
3. COUNT(column_name)
4. COUNT(*)

11. What is the result of this query?

SELECT AVG(marks) FROM Result;


1. Minimum mark
2. Count of students
3. Average marks
4. List of students

12. Which of the following statements is correct?


1. is case-sensitive
2. does not support arithmetic operations
3. SELECT * retrieves all columns
4. cannot filter records

13. Which clause is used to sort the result set?


1. GROUP BY
2. ORDER BY
3. HAVING
4. SORT BY

14. What does WHERE clause do in a query?


1. Inserts rows into a table
2. Orders the output
3. Filters rows based on condition
4. Groups similar rows

15. In , the symbol % in LIKE clause represents:


1. A comma
2. An exact match
3. A wildcard for zero or more characters
4. One digit only

16. What will this query output?

SELECT COUNT(*) FROM Employees WHERE dept = 'HR';


1. List of HR employees
2. Total number of HR employees
3. Names of employees
4. Salary of HR employees

17. In , which clause comes after WHERE when used together?


1. FROM
2. SELECT
3. GROUP BY
4. DISTINCT

18. Which of the following retrieves rows where the salary is between 5000 and 10000?

SELECT * FROM Employee WHERE salary BETWEEN 5000 AND 10000;


1. Correct
2. Incorrect syntax
3. Fetches only exact 5000 and 10000
4. Returns NULLs only

19. Which of the following is not a valid keyword?


1. INSERT
2. DROP
3. MERGE
4. COMBINE

20. The result of this query is:

SELECT dept, COUNT(*) FROM Employee GROUP BY dept;


1. Names of employees by department
2. Total departments
3. Number of employees in each department
4. Maximum salary per department

Sample Table: Employee

EmpID Name Dept Salary


101 Alice HR 50000
102 Bob IT 60000
103 Charlie IT 55000
104 David HR 52000
105 Eva Sales 48000

1.
Query:

SELECT Name FROM Employee WHERE Dept = 'HR';


What will be the output?
1. Alice, David
2. Bob, Charlie
3. Eva
4. Alice, Bob

2.
Query:

SELECT COUNT(*) FROM Employee WHERE Salary > 50000;


What is the result?
1. 3
2. 2
3. 4
4. 1

3.
Query:

SELECT Dept, AVG(Salary) FROM Employee GROUP BY Dept;


Which of the following is correct for Dept = 'HR'?
1. 50000
2. 51000
3. 52000
4. 53000

4.
Query:

SELECT MAX(Salary) FROM Employee WHERE Dept = 'IT';


What is the output?
1. 55000
2. 60000
3. 50000
4. 48000

5.
Query:

SELECT Name FROM Employee WHERE Name LIKE 'C%';


What will be returned?
1. Charlie
2. David
3. Alice
4. Eva

6.
Query:

SELECT COUNT(*) FROM Employee WHERE Dept IN ('HR', 'Sales');


What is the result?
1. 3
2. 4
3. 2
4. 1

7.
Query:

SELECT Dept FROM Employee GROUP BY Dept HAVING COUNT(*) > 1;


What is the output?
1. HR, IT
2. Sales
3. IT only
4. All departments

8.
Query:

SELECT Name FROM Employee ORDER BY Salary DESC LIMIT 1;


Who will be returned?
1. Eva
2. Bob
3. Charlie
4. David

9.
Query:

SELECT Dept, COUNT(*) as Total FROM Employee GROUP BY Dept;


Which of the following is correct?
1. HR – 2, IT – 2, Sales – 1
2. HR – 1, IT – 2, Sales – 2
3. HR – 2, IT – 1, Sales – 2
4. HR – 3, IT – 2, Sales – 1

10.
Query:

SELECT Name FROM Employee WHERE Salary BETWEEN 49000 AND 55000;
Which names will be returned?
1. Alice, Charlie, David
2. Eva, Charlie, David
3. Bob, Charlie
4. Eva, Alice

emp_id project_code start_date status


E101 PX-100 2023-01-15 Active
E205 PY-200 2023-02-20 Completed
E307 PZ-300 2023-03-10 Active
E412 PX-200 2023-01-25 On-Hold
E503 PY-100 2023-02-05 Completed

1.
Which emp_id is returned by Query 1 but not by Query 2?

-- Query 1
SELECT emp_id FROM EmployeeProjects WHERE status = 'Active';

-- Query 2
SELECT emp_id FROM EmployeeProjects WHERE status = 'Active' AND project_code LIKE 'PX%';
a) E101
b) E205
c) E307
d) E412

2.
Which emp_id has a status not present in any other record?

SELECT emp_id FROM EmployeeProjects WHERE status NOT IN (


SELECT status FROM EmployeeProjects GROUP BY status HAVING COUNT(*) > 1
);
a) E412
b) E101
c) E205
d) E503

3.
How many employees are on projects that start before the earliest 'Completed' project?
SELECT COUNT(*) FROM EmployeeProjects WHERE start_date < (
SELECT MIN(start_date) FROM EmployeeProjects WHERE status = 'Completed'
);
a) 1
b) 2
c) 3
d) 4

4.
Which emp_id is on an Active project with the latest start date?

SELECT emp_id FROM EmployeeProjects WHERE start_date = (


SELECT MAX(start_date) FROM EmployeeProjects WHERE status = 'Active'
);
a) E101
b) E307
c) E412
d) E503

5.
Who is assigned to the same project code as someone whose status is 'On-Hold'?

SELECT emp_id FROM EmployeeProjects WHERE project_code IN (


SELECT project_code FROM EmployeeProjects WHERE status = 'On-Hold'
);
a) E412
b) E101
c) None
d) No one else shares

Sample Table 2: Students

student_id name dept grade


S01 Ravi CSE B
S02 Neha CSE A
S03 Arjun ECE B
S04 Meera EEE A
S05 Sanya ECE C
6.
Who scored more than the average grade in CSE? (Assume A=3, B=2, C=1)

SELECT name FROM Students WHERE grade = 'A' AND dept = 'CSE';
a) Ravi
b) Neha
c) Meera
d) Arjun

7.
Which student is from a department not shared with anyone else?

SELECT name FROM Students WHERE dept NOT IN (


SELECT dept FROM Students GROUP BY dept HAVING COUNT(*) > 1
);
a) Meera
b) Neha
c) Ravi
d) Sanya

8.
Which student has the lowest grade in their department?

SELECT name FROM Students WHERE grade = (


SELECT MIN(grade) FROM Students WHERE dept = 'ECE'
);
a) Arjun
b) Sanya
c) Neha
d) Meera

9.
Which students belong to departments where at least one student scored A?

SELECT name FROM Students WHERE dept IN (


SELECT dept FROM Students WHERE grade = 'A'
);
a) Meera, Neha, Ravi
b) Meera, Neha
c) Meera, Ravi, Arjun
d) Sanya only

10.
What will the following query return?

SELECT COUNT(*) FROM Students WHERE grade = 'A' AND dept NOT IN (
SELECT dept FROM Students WHERE grade = 'C'
);
a) 1
b) 2
c) 0
d) 3

Sample Table 3: Sales

sale_id region amount


S001 North 2000
S002 East 3500
S003 North 2200
S004 West 3000
S005 East 3700

11.
Which region has the maximum sale?

SELECT region FROM Sales WHERE amount = (


SELECT MAX(amount) FROM Sales
);
a) North
b) East
c) West
d) South
12.
How many sales were above the average in the East region?

SELECT COUNT(*) FROM Sales WHERE region = 'East' AND amount > (
SELECT AVG(amount) FROM Sales WHERE region = 'East'
);
a) 0
b) 1
c) 2
d) 3

13.
Which sale_id is from the region with minimum total sales?

SELECT sale_id FROM Sales WHERE region = (


SELECT region FROM Sales GROUP BY region ORDER BY SUM(amount) ASC LIMIT 1
);
a) S004
b) S002
c) S001
d) S005

14.
Which sales are not in regions with total sales > 4000?

SELECT sale_id FROM Sales WHERE region NOT IN (


SELECT region FROM Sales GROUP BY region HAVING SUM(amount) > 4000
);
a) S001, S002
b) S004
c) S001, S003
d) S005

15.
How many sales belong to regions having more than one sale?

SELECT COUNT(*) FROM Sales WHERE region IN (


SELECT region FROM Sales GROUP BY region HAVING COUNT(*) > 1
);
a) 2
b) 4
c) 5
d) 3

Sample Table 4: Courses


course_id title credits
C101 DBMS 4
C102 OS 3
C103 Networks 3
C104 AI 5
C105 CyberSec 4

16.
Which course has the maximum credits?

SELECT title FROM Courses WHERE credits = (


SELECT MAX(credits) FROM Courses
);
a) OS
b) AI
c) DBMS
d) CyberSec

17.
Which courses have equal credits as any other course?

SELECT title FROM Courses WHERE credits IN (


SELECT credits FROM Courses GROUP BY credits HAVING COUNT(*) > 1
);
a) DBMS, CyberSec, OS
b) DBMS, CyberSec, Networks
c) AI, Networks
d) OS, AI

18.
What is the result of:

SELECT COUNT(*) FROM Courses WHERE credits > (


SELECT AVG(credits) FROM Courses
);
a) 2
b) 3
c) 1
d) 4

19.
Which course has less than all other credit values?

SELECT title FROM Courses WHERE credits < ALL (


SELECT credits FROM Courses
);
a) AI
b) OS
c) Networks
d) Both b and c

20.
Which course_id will be returned?

SELECT course_id FROM Courses WHERE title LIKE '%Sec' AND credits = (
SELECT MIN(credits) FROM Courses WHERE title LIKE '%Sec'
);
a) C105
b) C104
c) C102
d) None

Question 1
Table: RiverDetails(RiverName, Length, Country)
RiverName Length Country
Ganges 2525 India
Yangtze 6300 China
Amazon 6575 Brazil
Nile 6650 Egypt
São Francisco 2914 Brazil
Paraná 2914 Brazil
Query:

SELECT RiverName, Length


FROM RiverDetails rd1
WHERE Length = (
SELECT MAX(Length)
FROM RiverDetails rd2
WHERE rd1.Country = rd2.Country
);
What is the output?
a) All rivers
b) Ganges, Yangtze, Amazon, Nile
c) Ganges, Yangtze, Amazon, Nile, Paraná
d) Yangtze, Amazon, Nile, Paraná, São Francisco

✅ Question 2
Table: Product(PID, Price, Category)
PID Price Category
P1 500 Stationery
P2 1000 Electronics
P3 800 Electronics
P4 150 Stationery
P5 1200 Electronics
Query:

SELECT PID FROM Product p1


WHERE Price = (
SELECT MIN(Price)
FROM Product p2
WHERE p1.Category = p2.Category
);
What is returned?
a) P2, P4
b) P4, P3
c) P1, P3
d) P4, P3

✅ Question 3
Table: Employee(EID, Name, Salary, Dept)
EID Name Salary Dept
1 Arun 40000 IT
2 Bina 50000 HR
3 Carl 60000 IT
4 Divya 45000 HR
5 Emma 55000 IT
Query:
SELECT Name FROM Employee e1
WHERE Salary > (
SELECT AVG(Salary)
FROM Employee e2
WHERE e1.Dept = e2.Dept
);
What is the output?
a) Carl, Emma
b) Bina
c) Carl, Bina
d) Arun, Divya

✅ Question 4
Table: Books(Title, Year, Author)
Title Year Author
DBMS Concepts 2020 Korth
OS Principles 2021 Galvin
Python Basics 2020 Zed Shaw
AI Revolution 2023 Stuart R.
Networks 2020 Tanenbaum
Query:

SELECT Title FROM Books b1


WHERE Year = (
SELECT MAX(Year)
FROM Books b2
WHERE b1.Author = b2.Author
);
Output:
a) All books
b) Only “AI Revolution”
c) All latest books per author
d) Books published in 2020 only

✅ Question 5
Table: Marks(Student, Subject, Score)
Student Subject Score
Amit Math 88
Riya Math 92
Student Subject Score
Amit Science 85
Riya Science 81
Aman Math 75
Aman Science 95
Query:

SELECT Student FROM Marks m1


WHERE Score = (
SELECT MAX(Score)
FROM Marks m2
WHERE m1.Subject = m2.Subject
);
What is returned?
a) Amit, Riya
b) Riya, Aman
c) Riya only
d) Riya, Aman, Amit

✅ Question 6
Table: Flights(FlightNo, Source, Destination, Duration)
FlightNo Source Destination Duration
F101 NYC LA 5
F102 NYC SF 6
F103 NYC LA 4
F104 Miami SF 7
Query:

SELECT FlightNo FROM Flights f1


WHERE Duration = (
SELECT MIN(Duration)
FROM Flights f2
WHERE f1.Source = f2.Source
);
Output:
a) F101, F104
b) F103, F104
c) F102, F103
d) F103
✅ Question 7
Table: Students(Name, Department, CGPA)
Name Department CGPA
Anil CSE 8.5
Sita CSE 9.0
Rahul ECE 8.2
Tina ECE 9.1
Neha CSE 8.0
Query:

SELECT Name FROM Students s1


WHERE CGPA = (
SELECT MAX(CGPA)
FROM Students s2
WHERE s1.Department = s2.Department
);
Answer:
a) Sita, Tina
b) Anil, Rahul
c) Neha, Tina
d) Sita, Rahul

✅ Question 8
Table: City(Name, Country, Population)
Name Country Population
Mumbai India 20400000
Delhi India 18000000
Beijing China 21500000
Shanghai China 24200000
Cairo Egypt 9500000
Query:

SELECT Name FROM City c1


WHERE Population = (
SELECT MAX(Population)
FROM City c2
WHERE c1.Country = c2.Country
);
Answer:
a) Delhi, Beijing, Shanghai
b) Mumbai, Shanghai, Cairo
c) Mumbai, Shanghai, Cairo
d) Mumbai, Beijing, Cairo

✅ Question 9
Table: Enroll(Student, Course, Marks)
Student Course Marks
A DBMS 80
B DBMS 90
A OS 75
B OS 70
C DBMS 85
Query:

SELECT Student FROM Enroll e1


WHERE Marks = (
SELECT MAX(Marks)
FROM Enroll e2
WHERE e1.Course = e2.Course
);
Answer:
a) B
b) A, C
c) B, C
d) A only

✅ Question 10
Table: Vehicles(VID, Type, Price)
VID Type Price
V1 Car 700000
V2 Bike 80000
V3 Car 850000
V4 Truck 1200000
V5 Bike 65000
Query:

SELECT VID FROM Vehicles v1


WHERE Price = (
SELECT MAX(Price)
FROM Vehicles v2
WHERE v1.Type = v2.Type
);
Answer:
a) V3, V2, V4
b) V1, V2, V5
c) V3, V2, V4
d) V2, V5

Part A: Conceptual (Relational Model, Schema, Keys)


1. Which of the following best defines a relation in a relational database?
a) A logical collection of operations
b) A table with columns and rows
c) A collection of stored procedures
d) A hierarchical structure of data

2. A candidate key is:


a) Always composed of a single attribute
b) A set of attributes that uniquely identifies tuples
c) Same as a primary key
d) An attribute that cannot be null

3. Which of the following can never be null?


a) Primary key
b) Foreign key
c) Super key
d) Composite key

4. Which of these is not part of the relational model?


a) Relation
b) Attribute
c) Tuple
d) Pointer

5. What is the degree of a relation with schema Student(Roll, Name, Dept, Age)?
a) 3
b) 4
c) 2
d) 1

✅ Part B: Table-Based Query (Simulated output + logic)


Given Relation: StudentDetails(Roll, Name, Dept, Age)
Roll Name Dept Age
101 Amit CSE 20
102 Riya ECE 21
103 Anil CSE 22
104 Tina ME 21
105 Sayan ECE 20

6.

SELECT Name FROM StudentDetails WHERE Age = (


SELECT MAX(Age) FROM StudentDetails
);
a) Anil
b) Amit
c) Anil, Tina
d) Riya

7.

SELECT Dept FROM StudentDetails GROUP BY Dept;


How many rows will this query return?
a) 2
b) 3
c) 4
d) 5

8.

SELECT COUNT(*) FROM StudentDetails WHERE Dept = 'ECE';


a) 2
b) 3
c) 1
d) 4

9.

SELECT Name FROM StudentDetails WHERE Dept = (


SELECT Dept FROM StudentDetails WHERE Roll = 104
);
a) Tina
b) Riya
c) Tina, Anil
d) Amit

10.

SELECT Name FROM StudentDetails WHERE Age < (


SELECT AVG(Age) FROM StudentDetails
);
a) Amit, Sayan
b) Amit only
c) Riya
d) All

✅ Part C: Relational Schema, Attributes, and Keys


11. Which of the following is a superkey for relation R(A, B, C) with unique A?
a) {A}
b) {A, B}
c) {A, B, C}
d) All of the above

12. A relation can have:


a) Only one superkey
b) Only one candidate key
c) Many superkeys but one primary key
d) Only one foreign key

13. The total number of tuples in a relation is called:


a) Degree
b) Cardinality
c) Arity
d) Domain

14. In a relation with attributes (A, B, C), the number of subsets of attributes is:
a) 6
b) 8
c) 9
d) 7
15. Which of the following is not a valid operation in relational algebra?
a) Union
b) Join
c) Loop
d) Intersection

✅ Part D: Data-based Subquery and Output


Given Table: BookStore(BookID, Title, Author, Price)
BookID Title Author Price
B01 DBMS Korth 600
B02 OS Concepts Galvin 700
B03 Python Basics Zed Shaw 550
B04 AI Made Easy Stuart R. 800
B05 DBMS Navathe 750

16.

SELECT Title FROM BookStore WHERE Price = (


SELECT MAX(Price) FROM BookStore
);
a) OS Concepts
b) AI Made Easy
c) DBMS
d) DBMS, AI Made Easy

17.

SELECT COUNT(*) FROM BookStore WHERE Title = 'DBMS';


a) 1
b) 2
c) 3
d) 4

18.

SELECT Title FROM BookStore WHERE Price > (


SELECT AVG(Price) FROM BookStore
);
a) AI Made Easy, DBMS (Navathe), OS Concepts
b) All
c) None
d) DBMS only

19.

SELECT Title FROM BookStore WHERE Author = (


SELECT Author FROM BookStore WHERE BookID = 'B04'
);
a) AI Made Easy
b) OS Concepts
c) Python Basics
d) None

20.

SELECT Title FROM BookStore WHERE Price = (


SELECT MIN(Price) FROM BookStore
);
a) Python Basics
b) OS Concepts
c) AI Made Easy
d) DBMS

You might also like