This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1In Structured Query Language (SQL), what is the GROUP BY clause?
Option B
In SQL, the GROUP BY clause is used to arrange rows into groups based on the same values in one or more columns. It is commonly used with aggregate functions such as COUNT(), SUM(), AVG(), MAX(), and MIN().
The GROUP BY clause helps summarize data.
Table : Student
| Department | Students |
|---|---|
| CS | 50 |
| IT | 40 |
| CS | 30 |
| IT | 20 |
SELECT Department, SUM(Students)
FROM Student
GROUP BY Department;
| Department | Total Students |
|---|---|
| CS | 80 |
| IT | 60 |
Q: 2Which type of language allows a user to specify what task is to be done without specifying how the task will be accomplished?
Option C
A Query Language allows users to specify what data they want rather than how the data should be retrieved.
For example, in SQL, a user can write a query to fetch required records without worrying about the internal procedures used by the DBMS to access the data. This makes query languages Non-Procedural and easy to use.
Q: 3A technique called __________ can be used by malicious hackers to steal data or damage the database.
Option A
SQL Injection is a malicious technique in which attackers provide crafted input to SQL queries, tricking the database into executing unintended commands. This can lead to unauthorized data access, modification, or deletion. It is a major security concern for databases connected to web applications.
Q: 4Which SQL command is used to take back a privilege from a user?
Option B
In SQL, the REVOKE command is used to remove privileges that were previously granted to a user.
Q: 5Consider the SQL command, DELETE [FROM] table [WHERE condition]; What happens if the WHERE clause is omitted?
Option A
In SQL, the DELETE statement removes rows that satisfy the WHERE condition. If the WHERE clause is omitted, there is no condition to restrict the deletion, so all rows in the table are deleted. The table structure remains intact.
The SQL command DELETE FROM Student; deletes every record from the Student table.
Q: 6In SQL triggers, the action part can be executed in which of the following ways?
Option C
A Trigger in SQL is a set of actions automatically executed by the database in response to a specific event, such as an INSERT, UPDATE, or DELETE on a table. Triggers are often used for tasks like maintaining audit logs, enforcing business rules, or validating data automatically.
The action part of a trigger (the code that gets executed) can be performed in two ways:
Row-Level Trigger: The trigger is executed once for every row (tuple) that is modified by the operation.
Statement-Level Trigger: The trigger is executed only once, regardless of how many tuples are affected by the operation.
Q: 7Which of the following statement contains an error?
Option D
The error in this SQL statement occurs because the FROM clause is missing, which is required to specify the table from which data should be retrieved. A correct SELECT query must always include the FROM keyword followed by the table name. Additionally, if a column name contains spaces (for example, last name), it should be enclosed in quotes or brackets to avoid syntax errors.
| Syntax Pattern | Description |
|---|---|
| SELECT column1, column2, ... FROM table; | Select specific columns from a table. |
| SELECT * FROM table; | Select all columns from a table. |
| SELECT DISTINCT column FROM table; | Select unique or distinct values from a column. |
| SELECT column1, column2 FROM table WHERE condition; | Select with filtering rows based on condition. |
| SELECT column1, COUNT(*) FROM table GROUP BY column1; | Select grouped data with aggregation function. |
| SELECT column1, COUNT(*) FROM table GROUP BY column1 HAVING condition; | Grouped data with filtering on groups. |
| SELECT column1, column2 FROM table ORDER BY column1 ASC | Select specific columns from a table and arrange them either in ascending (ASC) or descending (DESC) order. |
| SELECT column1 INTO new_table FROM old_table; | Create new table by copying selected data from another table. |
| SELECT column1 FROM table1 JOIN table2 ON table1.col = table2.col; | Select data combining rows from two tables with join condition. |
Q: 8Which of the following helps a user to hide data in a database?
Option C
A View is a virtual table created using a SELECT query. It allows users to see only specific columns or rows of a table while hiding the remaining data. This is commonly used for data security and access control.
E.g.:
CREATE VIEW Employee_View AS
SELECT Empid, Name
FROM Employee;
Here, users can see only Empid and Name, while other sensitive columns like salary, designation, or address remain hidden.
Q: 9Consider the following data in Sailors table
| sid | sname | rating | age |
|---|---|---|---|
| 22 | Balu | 7 | 45 |
| 29 | Raghu | 1 | 33 |
| 31 | Parth | 8 | 55 |
| 32 | Ashok | 8 | 25 |
| 58 | Jaison | 10 | 35 |
| 64 | Swapna | 7 | 35 |
| 71 | Prasant | 10 | 25 |
| 74 | Ranjeet | 9 | 25 |
| 85 | Amala | 3 | 25 |
| 95 | Bindu | 3 | 35 |
| 96 | Prema | 3 | 25 |
The number of rows returned by below query is/are
Select S.ratingAvg(S.age) as avgage from Sailors S where
S.age>= 18
GROUP BY S.rating
HAVING 1 < (Select count(*) from Sailors S2 where S.rating = S2.rating)
Option C
In SQL, the GROUP BY clause is used to divide records into groups based on a column (rating).
The query then calculates an aggregate value (average age) for each group. The HAVING clause is used to filter these groups based on a condition.
| Rating | Number of Sailors | Condition (Count>1) |
|---|---|---|
| 7 | 2 | Yes |
| 1 | 1 | No |
| 8 | 2 | Yes |
| 10 | 2 | Yes |
| 9 | 1 | No |
| 3 | 3 | Yes |
After grouping the records based on rating and applying the condition that only those groups should be considered where the number of sailors is greater than one, we find that four ratings (7, 8, 10, 3) satisfy the condition.
Since the query returns one result (average age) for each valid group, the total number of rows returned is 4.
Q: 10Which of the following Oracle SQL statements is not correct?
Option C
In SQL, the ORDER BY clause is used to sort the result set based on one or more columns. By default, the sorting order is ascending (ASC). To sort in descending order, the DESC keyword is used. When sorting by multiple columns, the correct syntax is:
The sorting keyword (ASC or DESC) must always be written after the column name, not before it.
E.g.:
SELECT *
FROM Customers
ORDER BY Country ASC, CustomerName DESC;
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.