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. Indexes are only used in special cases

  2. Indexes are used to make table storage more efficient

  3. Indexes rarely make a difference in SQL performance

  4. Indexes exist solely to improve query speed

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

Indexes are database structures created to optimize query execution speed. While they consume extra storage space and can slow down data modification operations, their primary purpose is to enhance read performance.

Multiple choice technology testing
  1. UPDATE, DELETE, INSERT and SELECT statements.

  2. UPDATE statements only.

  3. DELETE statements only.

  4. INSERT statements only.

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

Subqueries can be nested within all Data Manipulation Language (DML) statements including UPDATE, DELETE, INSERT, and SELECT. This flexibility allows complex data operations to be performed in a single statement. Options B, C, and D are incorrect because they unnecessarily limit subqueries to only one type of statement.

Multiple choice technology databases
  1. Indexes are only used in special cases

  2. Indexes are used to make table storage more efficient

  3. Indexes rarely make a difference in SQL performance

  4. Indexes exist solely to improve query speed

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

Indexes are database structures created specifically to accelerate data retrieval operations. They provide fast lookup paths to rows without scanning entire tables. Option A is incorrect - indexes are commonly used. Option B is wrong - indexes add overhead to storage. Option C is false - indexes frequently dramatically improve query performance.

Multiple choice technology databases
  1. We are joining two tables only

  2. we are using left and right join together

  3. we are joining table to itself

  4. we are joining more than 2 tables

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

A self-join refers to a standard inner or outer join operation where a table is joined with itself. This is typically used to query hierarchical data stored within a single table by using aliases.

Multiple choice technology databases
  1. SELECT * FROM Contest WHERE ContestDate >= '05/25/2006'

  2. SELECT * FROM Contest GROUPBY ContestDate >= '05/25/2006'

  3. SELECT * FROM Contest WHERE ContestDate < '05/25/2006'

  4. SELECT * FROM Contest HAVING ContestDate >= '05/25/2006'

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

To solve this question, the user needs to know the syntax of SQL SELECT statements, how to select all rows from a table, how to specify column names, and how to use the WHERE clause to filter rows based on a certain condition.

Now, let's go through each option and explain why it is right or wrong:

A. SELECT * FROM Contest WHERE ContestDate >= '05/25/2006': This option is correct. This statement selects all columns and rows from the Contest table where the ContestDate column has a value greater than or equal to May 25, 2006. The date is specified in the format MM/DD/YYYY, which is a valid format for SQL.

B. SELECT * FROM Contest GROUPBY ContestDate >= '05/25/2006': This option is incorrect because it contains a syntax error. The GROUP BY clause is used to group rows based on a certain criteria, not to filter them. Also, the condition is not valid in the GROUP BY clause.

C. SELECT * FROM Contest WHERE ContestDate < '05/25/2006': This option is incorrect because it selects all rows from the Contest table where the ContestDate column has a value less than May 25, 2006. The question asks for values greater than or equal to that date.

D. SELECT * FROM Contest HAVING ContestDate >= '05/25/2006': This option is incorrect because the HAVING clause is used to filter rows based on a condition that involves an aggregate function. It cannot be used to filter rows based on a simple comparison like the one specified in this question.

The Answer is: A

Multiple choice technology databases
  1. returns all the matching rows from 2 tables.

  2. returns only the rows from the first table, which have non-matching values with the second table in the field on which the 2 tables are joined.

  3. returns all rows from 2 tables.

  4. returns all rows that have matching value in the field on which the 2 tables are joined.

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

An INNER JOIN selects and returns only the rows from both tables that satisfy the join condition (matching values in the specified fields). Rows that do not have matching values in both tables are excluded.

Multiple choice technology databases
  1. TRUNCATE Sales TABLE

  2. TRUNCATE * FROM TABLE Sales

  3. TRUNCATE TABLE Sales

  4. TRUNCATE * FROM COLUMN Sales

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

The correct TRUNCATE syntax in SQL is 'TRUNCATE TABLE table_name,' which removes all rows from a table while preserving its structure. TRUNCATE is a DDL operation that is faster than DELETE because it doesn't log individual row deletions. Options A, B, and D incorrectly mix TRUNCATE with other keywords or place TABLE in the wrong position.

Multiple choice technology databases
  1. SQL statements are not case-sensitive, unless indicated.

  2. Keywords can be abbreviated.

  3. SQL statements can be on one or more lines.

  4. Keywords cannot be split across lines.

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

SQL keywords cannot be abbreviated - they must be written in full (SELECT, FROM, WHERE, etc.). This is what makes statement B incorrect, and since the question asks which statement is 'not correct', B is the right choice. SQL statements are indeed case-insensitive unless the database is configured otherwise, can span multiple lines, and keywords cannot be split across lines.

Multiple choice technology databases
  1. A cursor is SQL keyword specifying a retrieved data order.

  2. Cursor is acronym for Current Set Of Records and is a database object pointing to a currently selected set of records.

  3. A blinking vertical line that indicates the location of the next input on the display screen.

  4. None of the above.

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

To solve this question, the user needs to have some understanding of databases and their operations.

Option A: This option is incorrect. The SQL keyword that specifies the order of retrieved data is "ORDER BY" and not "cursor."

Option B: This option is correct. A cursor is a database object that points to a currently selected set of records. It allows you to retrieve and manipulate data row by row. The term "cursor" comes from the idea of a cursor in a text editor, which is a movable indicator that shows where the next action will occur.

Option C: This option is incorrect. The blinking vertical line that indicates the location of the next input on the display screen is called a "cursor," but it is not related to database operations.

Option D: This option is incorrect because option B is the correct answer.

Therefore, The Answer is: B.

Multiple choice technology databases
  1. foo_text varchar2(10) := 'hello world';

  2. foo_char char(1) := 'Y';

  3. foo_number varchar2(10);

  4. foo_text number(10);

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

The incorrect variable declarations are A

  • A. foo_text varchar2(10) := 'hello world'; is incorrect because the variable foo_text is declared as a varchar2 type, but the initial value 'hello world' is a string. A varchar2 type can only store a sequence of characters, while a string can store a sequence of characters and other special characters, such as spaces and symbols.

The correct variable declarations are B, C, D.

  • B. foo_char char(1) := 'Y'; is correct because the variable foo_char is declared as a char type, which is a special type of varchar2 type that can only store a single character. The initial value 'Y' is a single character, so it is a valid value for the foo_char variable.
  • C. foo_number varchar2(10); is correct because the variable foo_number is declared as a varchar2 type, which can store a sequence of characters. The initial value 'hello world' is a sequence of characters, so it is a valid value for the foo_number variable.
  • D. foo_text number(10); is correct because the variable foo_text is declared as a number type, which can store an integer

Therefore, the correct answer is A.

Multiple choice technology databases
  1. SHOW MISTAKES;

  2. SHOW ERRORS;

  3. DISPLAY ERRORS;

  4. DISPLAY MISTAKES;

  5. None of the above.

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

The SHOW ERRORS (or SHOW ERR) command in SQL*Plus and SQL Developer displays the compilation errors associated with the most recently created or modified database object. Other options like SHOW MISTAKES are invalid SQL commands.