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

Multiple choice technology testing
  1. CREATE

  2. UNION

  3. WHERE

  4. OR

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

SQL injection attacks manipulate SQL queries by injecting malicious code. UNION is a key SQL operator used to combine results from injected queries with original results, allowing data extraction. OR is used to manipulate WHERE clause logic - a classic technique like 'OR 1=1' bypasses authentication by making conditions always true. CREATE is a DDL statement rarely used in injection. WHERE is a clause marker, not typically used alone for injection exploits. UNION and OR are fundamental to SQL injection techniques.

Multiple choice technology testing
  1. Buffer overflows

  2. SQL Injection

  3. Cross site scripting

  4. Authentication

  5. Authorization

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

Buffer overflows, SQL injection, and Cross-site scripting (XSS) are all attacks that exploit insufficient input validation. Buffer overflows occur when unchecked input exceeds memory boundaries. SQL injection happens when unvalidated input is concatenated into SQL queries. XSS results when unsanitized input is rendered in web pages. Authentication and Authorization (Options D, E) are security CONTROLS, not threat categories - they help prevent attacks but aren't attack types themselves. The claimed answer correctly identifies the three input validation threats.

Multiple choice technology testing
  1. SqlDataAdapter myCommand = new SqlDataAdapter( "SELECT CustomerName, Email, PhoneNo FROM users WHERE cust_id = '" + txtuser.Text + "'", myConnection);

  2. CREATE PROCEDURE procGetUser @custId VARCHAR(5) AS SELECT CustomerName, Email, PhoneNo FROM Customers WHERE cust_id = @custId

  3. SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT CustomerName, Email, PhoneNo FROM Customers WHERE cust_id = @cust_id", connection); myCommand.SelectCommand.Parameters.Add("@cust_id", SqlDbType.VarChar,

  4. All the above

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

String concatenation with user input (A) allows attackers to inject malicious SQL by crafting input like ' OR 1=1--. Options B and C use parameterized queries, which separate SQL code from data, making injection impossible.

Multiple choice technology testing
  1. CUST001' AND ‘1’=’1

  2. CUST1001' DROP TABLE OrderDetail --

  3. CUST1001’ OR 1 = 1--

  4. All the above

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

Option B attempts to drop a table using SQL injection. Option C uses 'OR 1=1--' to bypass authentication. Option A has mismatched quotes and won't work as written. 'All the above' (D) is incorrect since A is flawed.

Multiple choice technology programming languages
  1. EXISTS(n)

  2. EXTEND(n)

  3. LIMIT(n)

  4. SIZE(n)

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

In Oracle PL/SQL, the EXTEND(n) method adds n elements to the end of a collection (varray or nested table). EXISTS(n) checks if an element exists at position n, LIMIT returns the maximum size of varrays, and SIZE returns the current number of elements. Only EXTEND actually increases collection size.

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.