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

Multiple choice technology databases
  1. SELECT * FROM Persons SORT 'FirstName' DESC ;

  2. SELECT * FROM Persons ORDER BY FirstName DESC;

  3. SELECT * FROM Persons ORDER FirstName DESC ;

  4. SELECT * FROM Persons SORT BY 'FirstName' DESC ;

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

In SQL, sorting is performed using the ORDER BY clause, and descending order is specified with the DESC keyword. Therefore, ORDER BY FirstName DESC is correct. The other options use non-existent or invalid SQL keywords like SORT or omit the required BY keyword.

Multiple choice technology databases
  1. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen';

  2. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen ;

  3. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen' ;

  4. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen' ;

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

UPDATE table SET column=value WHERE condition is the standard SQL syntax. MODIFY and INTO are not valid keywords in UPDATE statements.

Multiple choice technology databases
  1. DELETE FROM Persons WHERE FirstName = 'Peter' ;

  2. DELETE FirstName='Peter' FROM Persons;

  3. DELETE ROW FirstName='Peter' FROM Persons ;

  4. TRUNCATE FROM Persons WHERE FirstName='Peter'

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

To solve this question, the user needs to know the basic syntax for deleting records in SQL, including the correct use of the DELETE command and WHERE clause.

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

A. DELETE FROM Persons WHERE FirstName = 'Peter' ; This option is correct. The DELETE command is used to delete records from a table in SQL. The WHERE clause is used to specify the condition that must be met for a record to be deleted. In this case, we want to delete all records where the FirstName is Peter, so we use the WHERE FirstName = 'Peter' condition.

B. DELETE FirstName='Peter' FROM Persons; This option is incorrect. The correct syntax for the DELETE command is DELETE FROM table_name, followed by the WHERE clause. In this option, the syntax is incorrect because the table name is missing, and the condition is in the wrong place.

C. DELETE ROW FirstName='Peter' FROM Persons ; This option is incorrect. The correct syntax for the DELETE command is DELETE FROM table_name, followed by the WHERE clause. In this option, the syntax is incorrect because the ROW keyword is not used in the correct way.

D. TRUNCATE FROM Persons WHERE FirstName='Peter' This option is incorrect. The TRUNCATE command is used to delete all records from a table, not specific records that meet a certain condition. Also, the syntax is incorrect because the WHERE clause is used in the wrong place.

The Answer is: A. DELETE FROM Persons WHERE FirstName = 'Peter' ;

Multiple choice technology databases
  1. SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson' ;

  2. SELECT * FROM Persons WHERE FirstName LIKE 'Peter' AND LastName LIKE 'Jackson';

  3. SELECT FirstName='Peter', LastName='Jackson' FROM Persons

  4. SELECT FirstName LIKE 'Peter', LastName LIKE 'Jackson' FROM Persons

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

Use WHERE with AND to combine multiple exact match conditions. LIKE is for pattern matching, not exact values. Option C incorrectly puts conditions in the SELECT clause.

Multiple choice technology databases
  1. SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen' ;

  2. SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen' ;

  3. SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons ;

  4. SELECT LastName LIKE'%Hansen%' AND LastName LIKE '%Pettersen%' FROM Persons ;

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

BETWEEN is the correct operator for range selection and is inclusive of both endpoints. The > and < operators in option A would exclude the boundary values.

Multiple choice technology databases
  1. INSERT ('Jimmy', 'Jackson') INTO Persons ;

  2. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons ;

  3. INSERT INTO Persons VALUES ('Jimmy', 'Jackson') ;

  4. INSERT VALUES ('Jimmy', 'Jackson') INTO Table Persons ;

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

INSERT INTO table VALUES (...) is the correct syntax. Options A and B have incorrect word order, and D incorrectly adds 'Table' keyword.

Multiple choice technology databases
  1. INSERT INTO Persons ('Olsen') INTO LastName ;

  2. INSERT INTO Persons (LastName) VALUES ('Olsen');

  3. INSERT ('Olsen') INTO Persons (LastName) ;

  4. INSERT INTO Table Persons (LastName) VALUES ('Olsen');

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

The standard SQL syntax for inserting a value into a specific column is INSERT INTO table_name (column_name) VALUES (value);. The correct option matches this syntax perfectly. The other options violate standard SQL syntax constraints by using incorrect keywords or incorrect placement of values.