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
  1. Unique Value

  2. Integer Data Type

  3. Not Null

  4. Foreign

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

A primary key uniquely identifies each record in a database table. Therefore, it must contain unique values and cannot contain NULL values. It does not have to be an integer, nor does it have to be a foreign key.

Multiple choice
  1. Connection Key

  2. Primary Key

  3. Candidate Key

  4. Foreign Key

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

A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It acts as a cross-reference between tables because it references the primary key or a unique key of another table.

Multiple choice
  1. DQL

  2. DML

  3. TCL

  4. DDL

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

INSERT, UPDATE, and DELETE are part of Data Manipulation Language (DML) because they are used to manage and manipulate data within existing schema objects. DDL is used for defining schemas, DQL for querying, and TCL for transaction control.

Multiple choice
  1. Every table must have a primary key

  2. Foreign keys must always reference a valid unique key

  3. Joins should only be used with foreign and primary keys

  4. Columns should be atomic

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

Referential integrity ensures that relationships between tables remain consistent. It requires that any foreign key field in a table must point to a valid, existing primary key or unique key in the referenced table, preventing orphaned records.

Multiple choice
  1. May throw NullPointerExceptions

  2. Have undefined behavior in logical expressions

  3. Represent the lack of a value for a column

  4. Are only valid in columns with the NULLABLE constraint

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

In SQL, NULL is a special marker used to indicate that a data value does not exist in the database. It represents missing, unknown, or inapplicable data, rather than a zero or an empty string.

Multiple choice
  1. Unique in the table

  2. Uniquely reference a primary key

  3. Unique in the row

  4. Unique in the column

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

The UNIQUE constraint ensures that all values in a specific column are different across all rows in the table. While this makes the values unique within that column across the table, the most precise description is that the values must be unique within that column.

Multiple choice
  1. composite key

  2. double-primary key

  3. consisting key

  4. foreign key

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

A composite key is a combination of two or more columns in a table that can be used to uniquely identify each row in the table. When multiple columns are combined to form a primary key, it is specifically referred to as a composite primary key.

Multiple choice
  1. Database

  2. cookie

  3. filed

  4. Dynamic

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

In computer science and general terminology, "dynamic" refers to systems or processes that are constantly changing, active, or progressing. A database is a structured set of data, a cookie is a small text file stored by a browser, and "filed" is a past tense verb or typo for field.

Multiple choice
  1. structured query language

  2. structured question language

  3. strong question language

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

SQL stands for Structured Query Language, which is the standard programming language used to manage and manipulate relational databases. It allows users to perform tasks such as querying, updating, and inserting data. The other options use incorrect words like 'question' instead of 'query'.

Multiple choice

Which of the following is a common technique used to mitigate SQL injection vulnerabilities?

  1. Input validation

  2. Use of prepared statements

  3. Escaping special characters

  4. All of the above

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

Input validation, use of prepared statements, and escaping special characters are all effective techniques to prevent SQL injection attacks.

Multiple choice

What is an elementary row operation?

  1. Adding a multiple of one row to another row.

  2. Multiplying a row by a nonzero constant.

  3. Swapping two rows.

  4. All of the above.

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

Elementary row operations are operations that can be performed on a matrix without changing the solution set of the corresponding system of linear equations. The three elementary row operations are adding a multiple of one row to another row, multiplying a row by a nonzero constant, and swapping two rows.

Multiple choice

What is the best way to protect against SQL injection attacks?

  1. Use parameterized queries

  2. Use input validation

  3. Keep your software up to date

  4. All of the above

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

The best way to protect against SQL injection attacks is to use parameterized queries, use input validation, and keep your software up to date.

Multiple choice

Which SQL statement is used to retrieve data from a database?

  1. SELECT

  2. INSERT

  3. UPDATE

  4. DELETE

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

The SELECT statement is used to retrieve data from a database. It allows you to specify the columns and rows to be retrieved, as well as filter and sort the results.

Multiple choice

What is the process of breaking down a complex query into smaller, more manageable subqueries called?

  1. Query Optimization

  2. Query Decomposition

  3. Query Transformation

  4. Query Rewriting

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

Query decomposition is the process of breaking down a complex query into smaller, more manageable subqueries. This helps improve query performance by reducing the number of accesses to the database and minimizing the amount of data that needs to be processed.