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

Multiple choice technology databases
  1. Group By

  2. Where

  3. Select

  4. Having

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Group functions

  2. Group by clause

  3. Distinct keyword

  4. All of above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Group functions

  2. Group by clause

  3. Distinct keyword

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. respective table data is retained

  2. data is deleted from table

  3. depends on conditions

  4. all of above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Group by clause

  2. Distinct keyword

  3. Pseudo column ROWNUM keyword

  4. All of above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. It is query with alias name

  2. It is subquery with alias name

  3. Both

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Unique key

  2. Primary key

  3. Foreign key

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. A column contains large no of values

  2. A column contains large no of null values

  3. Table is small

  4. When table is not updated frequently

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. Deletes rows from table

  2. Removes storage space

  3. Removes table structure

  4. All of the above

Reveal answer Fill a bubble to check yourself
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.'

Multiple choice technology databases
  1. set sqlprompt “Ravi Kishore > “

  2. set prompt “Ravi Kishore > “

  3. set sql “Ravi Kishore > “

  4. set sqlpromt “Ravi Kishore > “

Reveal answer Fill a bubble to check yourself
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).

Multiple choice technology databases
  1. delete from table_name where rowid not in (select max(rowid) from table group by duplicate_values_field_name);

  2. delete duplicate_values_field_name dv from table_name ta where rowid <(select min(rowid) from table_name tb where ta.dv=tb.dv);

  3. delete ename from emp a where rowid < ( select min(rowid) from emp b where a.ename = b.ename);

  4. Delete all

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. %Found

  2. %NOTFOUND

  3. %ROWCOUNT

  4. %ISOPEN

Reveal answer Fill a bubble to check yourself
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.