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
-
Back up the current transaction log. Restore the database with a different name and stop at
-
Back up the current transaction log. Restore the database to the point just before the data loss.
-
Restore the database from the existing backup files to a time just before the data loss.
-
Restore the database to the point of the last full backup.
A
Correct answer
Explanation
The key is to restore to a different database name (using the STOPAT option to specify time), then copy the missing table back. This avoids affecting the production database's availability while recovering the lost data.
A
Correct answer
Explanation
In SQL, the DISTINCT keyword must appear immediately after the SELECT keyword and before the column list. This syntax is mandatory - DISTINCT cannot appear elsewhere in the SELECT clause. The keyword is part of the SELECT clause syntax, not a separate clause.
-
select ename||',is the'||job from emp
-
select ename,||'is the||job from emp
-
select 'ename'||'is the'||'job' from from emp
-
select ename||concat('is the',job) from emp
A,C
Correct answer
Explanation
Option A correctly uses concatenation with || operator to combine columns and strings. Option C correctly concatenates string literals (quoted strings) - the column name 'ename' in quotes is a literal string, not a column reference, but this is valid SQL syntax. Options B and D have syntax errors.
-
Restrict result sets
-
Filter occurrences
-
Increase the query performance
-
None of the Above
A
Correct answer
Explanation
Filters restrict result sets by applying conditions that narrow the data returned. Option B ('Filter occurrences') is vague and not a standard database concept. Option C is incorrect because while filters can reduce data volume, their primary purpose is data restriction, not performance enhancement - that's a side effect, not the function itself.
-
SELECT
-
EXECUTE
-
ALTER TABLE
-
CREATE TABLE
-
DELETE
D
Correct answer
Explanation
CREATE TABLE is a system privilege that allows a user to create tables in their schema. SELECT, EXECUTE (when on procedures), DELETE, and ALTER TABLE are object privileges that must be granted on specific database objects. System privileges are schema-wide authorities, while object privileges operate on named objects.
-
string and date
-
character and numeric
-
integer and conversion
-
calendar and date
-
date and conversion
-
translation and date
B,E
Correct answer
Explanation
SQL provides built-in functions across multiple categories: character functions (SUBSTR, CONCAT, etc.), numeric functions (ABS, ROUND, etc.), date functions (SYSDATE, ADD_MONTHS, etc.), and conversion functions (TO_CHAR, TO_DATE, CAST, etc.). Option B correctly identifies character and numeric functions. Option E correctly identifies date and conversion functions. Option A is partially correct but incomplete. Options C, D, and F contain incorrect or non-standard category names.
-
A MERGE statement is used to merge the data of one table with data from another.
-
A MERGE statement can be used to update existing rows in a table.
-
A MERGE statement replaces the data of one table with that of another.
-
A MERGE statement can be used to insert new rows into a table.
-
The UNIQUE constraint does not permit a null value for the column.
-
The PRIMARY KEY and FOREIGN KEY constraints create a UNIQUE index.
-
The NOT NULL constraint ensures that null values are not permitted for the column.
-
A UNIQUE index gets created for columns with PRIMARY KEY and UNIQUE constraints.
A,C
Correct answer
Explanation
The UNIQUE constraint allows null values (unless combined with NOT NULL). A UNIQUE index is automatically created for columns defined with PRIMARY KEY and UNIQUE constraints, making that statement correct, while NOT NULL ensures no nulls are allowed.
-
A subquery should retrieve only one row.
-
A subquery can retrieve zero or more rows.
-
Subqueries CANNOT be nested by more than two levels.
-
A subquery can be used only in SQL query statements.
-
A subquery CANNOT be used in an SQL query statement that uses group functions.
-
When a subquery is used with an inequality comparison operator in the outer SQL statement,
B,F
Correct answer
Explanation
Subqueries can return zero, one, or multiple rows depending on context and operators used (B is true, disproving A). They can be nested beyond two levels in most databases (C is false). Subqueries can appear in various SQL statement types including DML and DDL, not just queries (D is false). They work with group functions (E is false). When using inequality operators with subqueries, single-row subqueries must be ensured or the ANY/ALL modifiers must be used (F is true, describing the inequality constraint requirement).
-
USER_CONSTRAINTS
-
USER_OBJECTS
-
ALL_CONSTRAINTS
-
USER_CONS_COLUMNS
-
USER_COLUMNS
D
Correct answer
Explanation
USER_CONS_COLUMNS displays the columns that participate in constraints defined on tables owned by the current user. USER_CONSTRAINTS shows constraint definitions but not column details. USER_OBJECTS lists all objects owned by the user. ALL_CONSTRAINTS includes constraints on accessible objects owned by others. USER_COLUMNS shows all table columns, not specifically constraint-related ones.
-
GRANT select ON dept TO ALL_USERS;
-
GRANT select ON dept TO ALL;
-
GRANT QUERY ON dept TO ALL_USERS
-
GRANT select ON dept TO PUBLIC;
-
GRANT QUERY ON dept TO PUBLIC;
D
Correct answer
Explanation
To grant all users query privileges, use GRANT select ON dept TO PUBLIC. PUBLIC is a reserved word that represents all database users. Option A incorrectly uses ALL_USERS which is not a valid grantee. Option B incorrectly uses ALL without PUBLIC. Option C incorrectly uses QUERY instead of SELECT and ALL_USERS. Option E incorrectly uses QUERY and incorrectly capitalizes PUBLIC.
-
UNIQUE
-
NOT NULL
-
CHECK
-
PRIMARY KEY
-
FOREIGN KEY
B
Correct answer
Explanation
The NOT NULL constraint can only be defined at the column level because it applies to a single column's values. Constraints like UNIQUE, CHECK, PRIMARY KEY, and FOREIGN KEY can be defined at either the column level or table level. Table-level constraints allow specification across multiple columns, which is essential for composite keys and multi-column conditions.
-
The tables being joined have NOT NULL columns.
-
The tables being joined have only matched data.
-
The columns being joined have NULL values.
-
The tables being joined have only unmatched data.
-
The tables being joined have both matched and unmatched data.
-
Only when the tables have a primary key/foreign key relationship.
C,E
Correct answer
Explanation
Outer joins preserve all rows from one or both tables, filling in NULLs where there are no matches. Use them when you need to keep unmatched rows (like finding customers with no orders) or when NULL values in join columns indicate non-matches rather than missing data. Inner joins only return matched rows, so outer joins are essential when unmatched data matters.
-
By Merging
-
By Sub Branching
-
By Creating a view
-
None of the above
A
Correct answer
Explanation
In version control systems, changes are propagated from one branch to another by performing a merge operation, which integrates the history and modifications.
-
INTEGER
-
REAL
-
NUMERIC (7,3)
-
DECIMAL(10,3)
D
Correct answer
Explanation
To store values up to 9999999.999, you need 7 digits before the decimal point and 3 digits after, requiring a total precision of 10. Thus, DECIMAL(10,3) is the correct data type.