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 SQL statement is used in embedded SQL to fetch data into host variables?
Option D
In embedded SQL, we write SQL statements inside a host programming language like C, Java, or COBOL. When we want to fetch data from a table and store it directly into host variables, we use the SELECT INTO statement.
The SELECT is used to read data from a table.
The INTO is used to store the fetched values into host language variables.
EXEC SQL SELECT column_name INTO :host_name FROM table_name WHERE condition;
E.g.:
Host variables in C:
char student_name[50];
int student_marks;
Embedded SQL SELECT INTO:
EXEC SQL SELECT name, marks
INTO :student_name, :student_marks
FROM Student
WHERE roll_no=101;
Q: 11SQL is a:
Option B
SQL (Structured Query Language) is a Non-Procedural or Declarative language, which means the user specifies what data is required, not how to retrieve it. The DBMS decides the best way to execute the query.
Q: 12In SQL, which of the following command(s) is (are) to remove rows from a table.
Option C
In SQL, rows or records from a table are removed using the DELETE command. It allows deleting specific rows using a condition (WHERE clause) or all rows if no condition is given.
TRUNCATE also removes all rows, but it is considered a DDL command and does not allow conditions, it deletes the entire table data at once, so it is not typically treated as a row-by-row removal operation.
Q: 13Which of the following is valid pair of schema change statements in SQL?
Option C
Schema change statements in SQL are used to modify the structure of existing database objects like tables, columns, or constraints. These changes can include adding or removing tables, columns, or other schema elements. The most common schema change statements are DROP and ALTER.
Q: 14Consider a table users(userid, country, city, street) with 50 million users.
DBA creates the following index for the table
CREATE INDEX myindex ON users(country, city, street)
For which of the following queries will this index be least useful?
Option B
The index is created on (country, city, street), which is a Composite Index. In a composite index, the database efficiently uses the index only when queries include the leftmost columns.
Queries using country or country and city can use the index. However, a query using only street skips the leading columns, so the index becomes least useful and the database may perform a full table scan.
Q: 15Which of the following database object does not physically exist?
Option C
A view in a database is a virtual table that represents the data retrieved by a stored SQL query from one or more base tables.
Unlike base tables and indexes, which physically exist and store data on disk, a view does not store data itself. Instead, it holds only the SQL query defining it.
When a user queries the view, the database engine executes the stored query dynamically on the underlying base tables to fetch the current data. This allows views to provide a customized and simplified representation of data, enforce security by controlling data access, and reduce complexity without duplicating storage.
Views serve as logical abstractions that help organize and present data efficiently without physically occupying storage space.
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.