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
  1. True

  2. False

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

External tables can accept data insertion in many database systems. For example, in Hive/Impala, you can insert data into external tables, though dropping the table won't delete the underlying data files. The statement claims data cannot be inserted, which is incorrect.

Multiple choice technology
  1. True

  2. False

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

External tables in most systems (including Netezza and Hive) do not support direct DELETE or TRUNCATE operations because they map to external files. You can't delete data from an external table without modifying the underlying file system directly.

Multiple choice technology databases
  1. Structured Question Language

  2. Structured Query Language

  3. Strong Question Language

  4. None

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

SQL stands for Structured Query Language, which is the standard language for relational database management systems. It is used for querying, manipulating, and defining data in databases.

Multiple choice technology databases
  1. SELECT

  2. UPDATE

  3. DELETE

  4. ALTER

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

DDL (Data Definition Language) statements define database structures. ALTER is a DDL command used to modify table structure. SELECT, UPDATE, and DELETE are DML (Data Manipulation Language) commands that operate on data within existing structures.

Multiple choice technology databases
  1. True

  2. False

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

SQL keywords are case-insensitive in most database systems. SELECT, Select, and select are all treated identically. However, string literals and identifier naming (depending on system) may be case-sensitive.

Multiple choice technology databases
  1. DROP

  2. DELETE

  3. TRUNCATE

  4. All the Above

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

The statement asks which SQL statement deletes a TABLE (not data). DROP TABLE completely removes the table structure and data from the database. DELETE removes rows but keeps the table, TRUNCATE removes all rows but keeps the table structure. Only DROP removes the table itself.

Multiple choice technology databases
  1. True

  2. False

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

The query uses LIKE '%la%' which matches any string containing 'la' anywhere (startswith, middle, or end). To match names starting with any character followed by 'la' (like 'Clara', 'Flavia'), the correct pattern would be '_la%' where underscore matches exactly one character. '%la%' matches 'Flamingo' (contains 'la'), not just patterns like '_la'.

Multiple choice technology databases
  1. SELECT LastName FROM Employee

  2. EXTRACT LastName FROM Employee

  3. SELECT Employee.LastName

  4. None

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

The SELECT statement is the standard SQL command for retrieving data from a database. The syntax 'SELECT column_name FROM table_name' correctly specifies which column to retrieve from which table. EXTRACT is not a valid SQL keyword for column retrieval, and 'SELECT Employee.LastName' would only work if using qualified notation with a table alias, which is not shown in the options.

Multiple choice technology databases
  1. SELECT *.Employee

  2. SELECT [all] FROM Employee

  3. SELECT * FROM Employee

  4. SELECT Employee

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

The asterisk () in SQL acts as a wildcard that represents all columns in a table. 'SELECT * FROM table_name' is the standard syntax to retrieve every column from the specified table. Options A and B use incorrect syntax ('.Employee' places the wildcard incorrectly, and '[all]' is not valid SQL syntax). Option D is missing both the column specification and FROM clause.

Multiple choice technology
  1. Update Employee set salary = salary * 1.5 and grade=’Promo’ where salary < 10000;

  2. Update Employee set salary = salary * 1.5, grade=’Promo’ where salary < 10000;

  3. Update table Employee set salary = salary * 1.5, grade=’Promo’ where salary < 10000;

  4. Update table Employee set salary = salary * 1.5 and grade=’Promo’ where salary < 10000;

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

The SQL UPDATE statement uses comma-separated assignments to update multiple columns, not the AND keyword. Option B correctly updates both salary (multiplied by 1.5) and grade (set to 'Promo') for rows where salary is less than 10000. Options A and D incorrectly use AND between column assignments, and option C unnecessarily includes the TABLE keyword which is not valid SQL syntax.

Multiple choice technology
  1. INSERT

  2. DELETE

  3. UPDATE

  4. CREATE

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

Data Definition Language (DDL) commands define database structures like tables, indexes, and schemas. CREATE is a DDL command used to create database objects. INSERT, DELETE, and UPDATE are Data Manipulation Language (DML) commands that manipulate data within existing structures.

Multiple choice technology
  1. PreparedStatement

  2. ParameterizedStatement

  3. ParameterizedStatement and CallableStatement

  4. All kinds of Statements (i.e. which implement a sub interface of Statement)

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

PreparedStatement is specifically designed to execute parameterized queries efficiently and safely. It pre-compiles SQL statements with placeholders (?) that are filled with parameter values at runtime, providing better performance and protection against SQL injection. Option B is fictional, and CallableStatement is for stored procedures.

Multiple choice technology
  1. CallableStatement

  2. ParameterizedStatement

  3. ParameterizedStatement and CallableStatement

  4. All kinds of Statements (i.e. which implement a sub interface of Statement)

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

CallableStatement executes stored procedures and functions that reside on the database server. It extends PreparedStatement and accepts parameters including OUT parameters for retrieving values from stored procedures. This allows executing complex logic encapsulated in database routines rather than embedding it in application code.

Multiple choice technology
  1. The executeUpdate method returns all the rows that were affected

  2. The executeUpdate method returns the no. of rows that were affected

  3. Depends , as there is more than one version of this method with different return types

  4. NONE

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

The executeUpdate() method returns an integer representing the number of rows affected by INSERT, UPDATE, or DELETE operations. This allows applications to verify whether the operation succeeded. Option A is imprecise (doesn't specify what's returned), and option C is incorrect; there's only one executeUpdate method signature that returns int.