Computer Knowledge

Database and SQL

3,929 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
  1. Revoke

  2. Rollback

  3. Savepoint

  4. Commit

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

ROLLBACK is the TCL command that undoes all changes made in the current transaction, restoring the database to its state before transaction began. COMMIT saves changes permanently. REVOKE is for permissions (DCL). SAVEPOINT marks a transaction point for partial rollback.

Multiple choice
  1. Delete

  2. Remove

  3. Truncate

  4. Both (1) and (3)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In SQL, DELETE removes specific rows based on a condition, while TRUNCATE removes all rows from a table quickly by de-allocating data pages. Both commands are used to remove rows - DELETE is more flexible for selective removal, while TRUNCATE is faster for complete table clearing. REMOVE is not a standard SQL command for this purpose.

Multiple choice
  1. Delete Table

  2. Drop table

  3. Erase Table

  4. None of above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

DROP is the SQL command used to permanently remove database objects like tables and indexes. DELETE removes rows from a table but doesn't delete the table structure itself. DROP is part of Data Definition Language (DDL) operations.

Multiple choice
  1. Select distinct

  2. Select unique

  3. Select different

  4. None of above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

SELECT DISTINCT is the SQL command that eliminates duplicate rows from query results, returning only unique values. DISTINCT is a keyword that filters out repeated rows in the specified columns. SELECT UNIQUE and SELECT DIFFERENT are not valid SQL syntax.

Multiple choice
  1. Schema, Base and Table

  2. Base, Table and Schema

  3. Key, Base and Table

  4. Schema, Table and View

  5. None of these

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

SQL DDL (Data Definition Language) includes CREATE commands for Schema, Table, and View. These define the structure and relationships in a database. CREATE TABLE defines tables, CREATE VIEW defines virtual tables, and CREATE SCHEMA defines logical database groupings.

Multiple choice
  1. There is a syntax error in the query.

  2. It may return one row if the STUDENT_ID 119 is present in the table else it will return zero rows.

  3. It always returns zero rows.

  4. It returns n number of rows, where n is the number of students whose STUDENT_ID is 119.

  5. It returns all the rows in the table irrespective of the data.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Yes, it is true.

Multiple choice
  1. SELECT * FROM STUDENTS WHERE STUDENT_ID = 119 OR COURSE_ID = 301

  2. SELECT ALL FROM STUDENTS WHERE STUDENT_ID = 119 OR COURSE_ID = 301

  3. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE STUDENT_ID = 119 OR COURSE_ID = 301

  4. SELECT ALL STUDENT_ID FROM STUDENTS WHERE STUDENT_ID = 119 OR COURSE_ID = 301

  5. All of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Yes, this is the correct syntax.

Multiple choice
  1. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MAX(MARKS)

  2. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MARKS = ( SELECT MAX(MARKS) FROM STUDENTS )

  3. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MARKS = MAX(MARKS)

  4. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MARKS = MAX

  5. All of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Yes, it is true.

Multiple choice
  1. Subqueries are mainly of two types - nested and correlated.

  2. A subquery usually have an outer query and an inner query.

  3. A subquery can be written using either a single or multiple tables.

  4. Generally, the innermost subquery is executed first and based on its results, outer queries will execute.

  5. All of the above

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Yes, all of the above statements are correct.

Multiple choice
  1. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MARKS > 123

  2. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MARKS > ( STUDENT_ID = 123 )

  3. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MARKS > 123 ( SELECT MARKS FROM STUDENTS WHERE STUDENT_ID = 123 )

  4. SELECT STUDENT_ID, MARKS FROM STUDENTS WHERE MARKS > ( SELECT MARKS FROM STUDENTS WHERE STUDENT_ID = 123 )

  5. All of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Yes, it returns the desired result.

Multiple choice
  1. It always returns only one row with STUDENT_ID 123.

  2. It does not return any row as MARKS cannot be compared with STUDENT_ID.

  3. It returns n number of rows, where n is the number of students whose marks are greater than that of student whose STUDENT_ID is 123.

  4. It returns all the rows in the query.

  5. There is syntax error in the query.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Yes, it returns n number of rows, where n is the number of students whose marks are greater than that of student whose STUDENT_ID is 123. So, this option is correct.

Multiple choice
  1. There is a syntax error in this query.

  2. Only one row will be returned irrespective of the data.

  3. It always returns zero rows.

  4. It returns n number of rows, where n is the number of students whose marks are greater than 80.

  5. It returns all the rows in the table.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Yes, it is true. n varies with the data in the table.