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 programming languages
  1. DROP, DELETE

  2. TRUNCATE, DROP

  3. DROP, TRUNCATE

  4. DELETE, DROP

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

TRUNCATE removes all rows from a table while keeping the table structure. DROP completely removes the table including its structure, and some databases move it to a recycle bin. The question asks for 'remove rows but not structure' first, then 'entire table removed'.

Multiple choice technology mainframe
  1. True

  2. False

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

Keyword parameters (Parms) in job control systems typically handle only the current date or job submission time. They do not inherently support calculating advance or future dates, nor retrieving past dates relative to the current date. This limitation is by design to keep job control simple and deterministic.

Multiple choice technology mainframe
  1. sqlcode

  2. sqlwarn

  3. sqlstate

  4. sqlsdmp

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

SQLCA (SQL Communications Area) is a DB2 structure that provides information about SQL statement execution. The standard fields include SQLCODE (return code), SQLWARN (warning flags), and SQLSTATE (status code). SQLSDMP is not a standard SQLCA field - it's a distractor. SQLCA is defined in IBM's DB2 documentation and SQL standards.

Multiple choice technology mainframe
  1. OPEN

  2. GET

  3. INTO

  4. SELECT

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

SELECT is the fundamental SQL statement used to retrieve and extract data from database tables. It specifies which columns to retrieve and from which tables, optionally with filtering, sorting, and aggregation. OPEN is for cursors, GET is not a SQL keyword in this context, and INTO is used for specifying output variables in embedded SQL, not for extraction itself.

Multiple choice technology databases
  1. We are using left and right join together

  2. We are joining more than 2 tables

  3. We are joining table to itself

  4. we are joining 2 tables

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

To solve this question, the user needs to know the concept of self-join in database management systems.

A self-join is a regular join, but the table is being joined with itself. This means that we are using a single table to compare rows within the same table.

Option A is incorrect because a left and right join is not referred to as a self-join.

Option B is incorrect because the number of tables being joined does not determine whether a self-join is being used or not.

Option D is incorrect because a regular join between two tables is not referred to as a self-join.

Therefore, the correct answer is:

The Answer is: C. We are joining table to itself.

Multiple choice technology databases
  1. The AS clause is used with the JOIN clause only.

  2. The AS SQL clause is used change the name of a column in the result set or to assign a name to a derived column.

  3. The AS clause defines a search condition.

  4. The AS clause defines a join

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

The AS clause in SQL is used to create column aliases - it renames a column in the query result or assigns a name to a calculated/derived column. It improves readability of output and allows referencing derived columns in other clauses (like ORDER BY). It is not specific to JOINs, does not define search conditions, and does not define joins.

Multiple choice technology databases
  1. a column list.

  2. a table list.

  3. a list of values.

  4. a range to test in the SQL query search condition.

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

BETWEEN is a SQL operator that selects values within a given range, inclusive of both endpoints. It's a shorthand for using >= and <= comparisons together. The syntax is 'BETWEEN value1 AND value2' which specifies a range to test in WHERE clauses. It doesn't specify column lists, table lists, or simple value lists - those use IN or other operators.

Multiple choice technology databases
  1. UNIQUE

  2. DIFFERENT

  3. DISTINCT

  4. DISTINCTIVE

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

DISTINCT is the SQL keyword used to retrieve only unique values from a column, eliminating duplicate rows in the result set. UNIQUE is a constraint used during table creation to enforce uniqueness, not for data retrieval. DIFFERENT and DISTINCTIVE are not valid SQL keywords.

Multiple choice technology programming languages
  1. It will select only the field on which the keyword is specified.

  2. It will select only one record.

  3. It will avoid to enter duplicate key values.

  4. None of the above.

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

The UNIQUE keyword in DDS prevents duplicate key values from being entered into a database file. It enforces data integrity at the file level. It does not select fields or records - it's a constraint, not a selection tool.

Multiple choice technology databases
  1. SAVE

  2. MODIFY

  3. UPDATE

  4. SAVE AS

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

The UPDATE statement is the SQL command used to modify existing data in database tables. Options A, B, and D (SAVE, MODIFY, SAVE AS) are not valid SQL statements - these sound like application commands, not database operations. UPDATE is paired with SET and WHERE clauses to change specific records.

Multiple choice technology databases
  1. ADD RECORD

  2. ADD NEW

  3. INSERT

  4. INSERT NEW

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

The INSERT statement is the SQL command used to add new records to database tables. Options A, B, and D (ADD RECORD, ADD NEW, INSERT NEW) are not valid SQL syntax. The correct command is simply INSERT, typically used with INSERT INTO followed by VALUES or a SELECT statement.

Multiple choice technology databases
  1. SELECT [all] FROM Persons ;

  2. SELECT *. FROM Persons ;

  3. SELECT *.Persons ;

  4. SELECT * FROM Persons ;

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

The correct SQL syntax to select all columns is 'SELECT * FROM tablename' where the asterisk (*) is a wildcard representing all columns. Option A incorrectly uses square brackets, option B has an erroneous period after the asterisk, and option C has incorrect dot notation. The semicolon at the end is optional but correct.

Multiple choice technology databases
  1. SELECT [all] FROM Persons WHERE FirstName='Peter' ;

  2. SELECT * FROM Persons WHERE FirstName='Peter' ;

  3. SELECT * FROM Persons WHERE FirstName LIKE 'Peter' ;

  4. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter' ;

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

The correct syntax is 'SELECT * FROM Persons WHERE FirstName='Peter'' which uses the WHERE clause with an equality operator. Option A incorrectly uses square brackets, while options C and D use LIKE operator which is for pattern matching, not exact values. The WHERE clause filters rows based on specified conditions.

Multiple choice technology databases
  1. SELECT * FROM Persons WHERE FirstName LIKE '%a';

  2. SELECT * FROM Persons WHERE FirstName='a' ;

  3. SELECT * FROM Persons WHERE FirstName LIKE 'a%' ;

  4. SELECT * FROM Persons WHERE FirstName='%a%;

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

The correct syntax is 'SELECT * FROM Persons WHERE FirstName LIKE 'a%'' which uses the LIKE operator with a wildcard pattern. The percent sign (%) matches any sequence of characters, so 'a%' finds strings starting with 'a'. Option A finds strings ending with 'a', option B checks for exact equality, and option D has incorrect syntax with misplaced quotes and wildcard.