Computer Knowledge
Database and SQL
4,213 Questions
Master structured query language commands, database joins, table constraints, and alias generation. This section covers relational database management concepts and query outputs essential for technical aptitude. These technical questions feature prominently in banking IT officer exams and computer knowledge sections.
SQL queries and aliasesDatabase table constraintsDatabase joins and transformationsStored procedures and functions
Database and SQL Questions
-
Group By
-
Where
-
Select
-
Having
A
Correct answer
Explanation
In standard SQL, GROUP BY cannot reference column aliases defined in the SELECT clause. The statement uses alias 'Departments' in GROUP BY, which is invalid in most databases (Oracle, SQL Server). GROUP BY must use the original column name 'dept_no', not the alias.
C
Correct answer
Explanation
SELECT is the standard SQL command for retrieving data from databases. OPEN is used for cursors, GET is not a standard SQL command, and EXTRACT is a function for retrieving date/time components, not data extraction.
-
Group functions
-
Group by clause
-
Distinct keyword
-
All of above
D
Correct answer
Explanation
Views cannot be used for DELETE if they contain GROUP BY, DISTINCT, or group functions (aggregate functions like COUNT, SUM). These constructs create derived/aggregate data that cannot be mapped back to individual rows.
-
Group functions
-
Group by clause
-
Distinct keyword
-
All of the above
D
Correct answer
Explanation
Views cannot be used for DELETE if they contain GROUP BY, DISTINCT, or group functions (aggregate functions like COUNT, SUM). These constructs create derived/aggregate data that cannot be mapped back to individual rows.
-
respective table data is retained
-
data is deleted from table
-
depends on conditions
-
all of above
A
Correct answer
Explanation
Dropping a view removes only the view definition (metadata). The underlying table and its data are completely unaffected - views are virtual tables, not data storage.
-
Group by clause
-
Distinct keyword
-
Pseudo column ROWNUM keyword
-
All of above
D
Correct answer
Explanation
Views with GROUP BY, DISTINCT, or pseudo columns like ROWNUM cannot be modified through DML operations. These constructs create results that cannot be mapped back to base table rows for updates or deletes.
-
It is query with alias name
-
It is subquery with alias name
-
Both
-
None of the above
B
Correct answer
Explanation
An inline view is a subquery in the FROM clause that has a correlation name (alias). It acts like a temporary table within the query scope, unlike a regular view which is a stored schema object.
-
Unique key
-
Primary key
-
Foreign key
-
All of the above
B
Correct answer
Explanation
Sequences generate unique numeric values in databases, which are most commonly used to populate primary key columns when inserting new records. While sequences can technically generate values for any unique identifier, their primary purpose is generating auto-incrementing values for primary keys. Option D is incorrect because sequences specifically generate numbers, not all types of keys.
-
A column contains large no of values
-
A column contains large no of null values
-
Table is small
-
When table is not updated frequently
C
Correct answer
Explanation
Indexes provide performance benefits primarily on large tables by speeding up data retrieval. On small tables, the overhead of maintaining the index outweighs any performance gain, and a full table scan is already fast. Options A and B are actually scenarios where indexes might be useful (high cardinality columns), while Option D is incorrect because indexes are beneficial regardless of update frequency.
-
Deletes rows from table
-
Removes storage space
-
Removes table structure
-
All of the above
C
Correct answer
Explanation
TRUNCATE is a DDL command that quickly removes all rows from a table and deallocates the storage space, but it does NOT remove the table structure itself - that would be DROP TABLE. Unlike DROP TABLE which completely removes the table definition, TRUNCATE keeps the table schema intact with all columns and constraints. Options A and B are both correct descriptions of what TRUNCATE does, making C the only option that is 'not right.'
-
Candidate key
-
Member key
-
Both of above
-
None of the above
-
set sqlprompt “Ravi Kishore > “
-
set prompt “Ravi Kishore > “
-
set sql “Ravi Kishore > “
-
set sqlpromt “Ravi Kishore > “
A
Correct answer
Explanation
In SQL*Plus, the command set sqlprompt is used to change the command prompt string. The distractors are invalid command names (set prompt is used for other prompt styles, while sql and sqlpromt are syntactically incorrect in SQL*Plus).
-
delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);
-
delete duplicate_values_field_name dv from table_name ta where rowid <(select min(rowid) from table_name tb where ta.dv=tb.dv);
-
delete ename from emp a where rowid < ( select min(rowid) from emp b where a.ename = b.ename);
-
Delete all
A,B,C
Correct answer
Explanation
All three approaches (A, B, C) are valid SQL techniques for deleting duplicate rows while keeping one instance. They use ROWID (Oracle) or equivalent row identifiers to identify and delete duplicates. Option A keeps the max ROWID; B and C keep the min ROWID per duplicate group. Option D would delete everything.
-
%Found
-
%NOTFOUND
-
%ROWCOUNT
-
%ISOPEN
A,B,C,D
Correct answer
Explanation
All four are valid explicit cursor attributes in PL/SQL. %FOUND returns TRUE if the last fetch returned a row. %NOTFOUND is the opposite. %ROWCOUNT counts rows fetched so far. %ISOPEN indicates whether the cursor is currently open. These attributes are essential for controlling cursor-based processing.
-
No_Data_Found
-
Too_many_rows
-
Value_Error
-
Zero_Error