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 technology databases
  1. SELECT * FROM Persons SORT BY 'FirstName' DESC

  2. SELECT * FROM Persons SORT 'FirstName' DESC

  3. SELECT * FROM Persons ORDER BY FirstName DESC

  4. SELECT * FROM Persons ORDER FirstName DES

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

The correct SQL syntax uses ORDER BY (not SORT BY) with DESC for descending order. Options A and B use SORT BY which is incorrect. Option D has incomplete DESC keyword and missing BY. The standard syntax is: SELECT * FROM table ORDER BY column DESC.

Multiple choice technology databases
  1. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons

  2. INSERT ('Jimmy', 'Jackson') INTO Persons

  3. INSERT INTO Persons VALUES ('Jimmy', 'Jackson')

  4. None

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

The correct SQL syntax for inserting a record is INSERT INTO table_name VALUES (value1, value2...). Option C shows this correctly. Options A and B have incorrect syntax (INSERT VALUES instead of INSERT INTO VALUES, and INSERT ... INTO instead of INSERT INTO ...).

Multiple choice technology databases
  1. INSERT INTO Persons ('Olsen') INTO LastName

  2. INSERT ('Olsen') INTO Persons (LastName)

  3. INSERT INTO Persons (LastName) VALUES ('Olsen')

  4. None

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

When inserting into specific columns, use INSERT INTO table_name (column1, column2...) VALUES (value1, value2...). Option C correctly shows inserting into the LastName column only. Options A and B have incorrect syntax.

Multiple choice technology databases
  1. DELETE ROW FirstName='Peter' FROM Persons

  2. DELETE FROM Persons WHERE FirstName = 'Peter'

  3. DELETE FirstName='Peter' FROM Persons

  4. None

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

The standard SQL syntax to delete specific records from a table is 'DELETE FROM table_name WHERE condition'. Thus, 'DELETE FROM Persons WHERE FirstName = 'Peter'' is correct.

Multiple choice technology databases
  1. SELECT COLUMNS() FROM Persons

  2. SELECT COUNT(*) FROM Persons

  3. SELECT COUNT() FROM Persons

  4. SELECT COLUMNS(*) FROM Persons

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

To count records in SQL, use the COUNT(*) aggregate function. Option B shows the correct syntax. COUNT() without asterisk (option C) is incomplete, and SELECT COLUMNS() is not valid for counting records.

Multiple choice technology databases
  1. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'

  2. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen

  3. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'

  4. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen

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

The standard SQL syntax to modify data uses the UPDATE statement combined with SET to assign the new value and a WHERE clause to specify which rows to change.

Multiple choice technology enterprise content management
  1. Having a single SQL query with FACT A, FACT B and Conf D.

  2. Have a individual query between FACT A & Conf D, and a individual query between FACT B & Conf D.

  3. Have three individual queries, one for each table.

  4. A and B

  5. All of the above

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

With conformed dimensions, the best practice is to query each fact table separately against the shared dimension (individual queries). A single query joining both facts directly would create a snowflake pattern that can cause performance issues and incorrect results due to fact table explosion (cartesian product of fact rows).

Multiple choice technology databases
  1. col$
  2. aud$
  3. row$
  4. none

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

AUD$ is the audit trail table in Oracle that can be modified, typically for maintenance purposes like truncating old audit records. Other SYS tables like COL$ and ROW$ are data dictionary tables that should never be directly modified.

Multiple choice technology programming languages
  1. Names are case sensitive.

  2. Names must not be oracle server reserve word.

  3. Table names and column names need not be start with a letter.

  4. We cannot use a column alias in a WHERE clause

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

In Oracle SQL, table/column names cannot be reserved words (like SELECT, FROM, etc.) without quoting. Column aliases (defined in SELECT clause) cannot be used in WHERE clause because WHERE is processed before SELECT. Names are case-insensitive and must start with a letter.

Multiple choice technology programming languages
  1. Select

  2. Insert

  3. Update

  4. Create

  5. Delete

  6. Alter

Reveal answer Fill a bubble to check yourself
A,B,C,E Correct answer
Explanation

DML (Data Manipulation Language) commands operate on existing data within database objects. SELECT retrieves data, INSERT adds new rows, UPDATE modifies existing data, and DELETE removes rows. CREATE and ALTER are DDL (Data Definition Language) commands that define or modify database structures, not manipulate data.

Multiple choice technology programming languages
  1. The column contain wide range of values.

  2. The column contain large number of Null values.

  3. The table is large.

  4. Columns which are not frequently used.

Reveal answer Fill a bubble to check yourself
A,B,C Correct answer
Explanation

Indexes are beneficial when columns contain wide range of values (high cardinality), when tables are large (performance impact is significant), and when columns contain many NULL values (indexes can efficiently skip NULLs). Columns that are infrequently used don't benefit from indexing as the query performance gain wouldn't justify the storage and maintenance overhead.

Multiple choice technology databases
  1. When an entire index is scanned to locate rows we call it as index scan

  2. When only part of the index is scanned to locate rows we call it as index scan

  3. When all the rows are scanned we call it as index scan

  4. None of the above

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

An index scan occurs when DB2 accesses and searches the index structure itself to locate the requested rows, rather than scanning the entire tablespace.

Multiple choice technology databases
  1. Complex Key

  2. Secondary Key

  3. Composite Key

  4. Foreign Key

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

A composite key is a key that consists of two or more columns used together to uniquely identify a row in a table. Unlike a simple key that uses a single column, composite keys combine multiple columns to ensure uniqueness when no single column can uniquely identify records.