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
-
Revoke
-
Rollback
-
Savepoint
-
Commit
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.
-
Delete
-
Remove
-
Truncate
-
Both (1) and (3)
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.
-
Delete Table
-
Drop table
-
Erase Table
-
None of above
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.
-
Select distinct
-
Select unique
-
Select different
-
None of above
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.
-
Select all from Table_Name
-
Select * Table_Name
-
Select full from Table_Name
-
Select full Table_Name
-
Select * from Table_Name
E
Correct answer
Explanation
Yes, it displays all the data that exist in the table.
-
Delete statement
-
Insert statement
-
Update statement
-
All the above
-
None of these
D
Correct answer
Explanation
Yes, Delete, Insert and Update change the data in the table.
-
Schema, Base and Table
-
Base, Table and Schema
-
Key, Base and Table
-
Schema, Table and View
-
None of these
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.
-
date + number
-
date - number
-
date - date
-
date + (number/24)
-
none of the above
C
Correct answer
Explanation
Difference between two dates returns a number. This output is different while others return only DATE.
-
There is a syntax error in the query.
-
It may return one row if the STUDENT_ID 119 is present in the table else it will return zero rows.
-
It always returns zero rows.
-
It returns n number of rows, where n is the number of students whose STUDENT_ID is 119.
-
It returns all the rows in the table irrespective of the data.
-
SELECT *
FROM STUDENTS
WHERE STUDENT_ID = 119
OR COURSE_ID = 301
-
SELECT ALL
FROM STUDENTS
WHERE STUDENT_ID = 119
OR COURSE_ID = 301
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE STUDENT_ID = 119
OR COURSE_ID = 301
-
SELECT ALL STUDENT_ID
FROM STUDENTS
WHERE STUDENT_ID = 119
OR COURSE_ID = 301
-
All of the above
C
Correct answer
Explanation
Yes, this is the correct syntax.
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MAX(MARKS)
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MARKS =
(
SELECT MAX(MARKS)
FROM STUDENTS
)
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MARKS = MAX(MARKS)
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MARKS = MAX
-
All of the above
-
Subqueries are mainly of two types - nested and correlated.
-
A subquery usually have an outer query and an inner query.
-
A subquery can be written using either a single or multiple tables.
-
Generally, the innermost subquery is executed first and based on its results, outer queries will execute.
-
All of the above
E
Correct answer
Explanation
Yes, all of the above statements are correct.
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MARKS > 123
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MARKS > ( STUDENT_ID = 123 )
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MARKS > 123
(
SELECT MARKS
FROM STUDENTS
WHERE STUDENT_ID = 123
)
-
SELECT STUDENT_ID, MARKS
FROM STUDENTS
WHERE MARKS >
(
SELECT MARKS
FROM STUDENTS
WHERE STUDENT_ID = 123
)
-
All of the above
D
Correct answer
Explanation
Yes, it returns the desired result.
-
It always returns only one row with STUDENT_ID 123.
-
It does not return any row as MARKS cannot be compared with STUDENT_ID.
-
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.
-
It returns all the rows in the query.
-
There is syntax error in the query.
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.
-
There is a syntax error in this query.
-
Only one row will be returned irrespective of the data.
-
It always returns zero rows.
-
It returns n number of rows, where n is the number of students whose marks are greater than 80.
-
It returns all the rows in the table.
D
Correct answer
Explanation
Yes, it is true. n varies with the data in the table.