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

  2. Function

  3. Table

  4. View

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

Triggers are primarily associated with tables and execute in response to INSERT, UPDATE, or DELETE operations on that table. While INSTEAD OF triggers can also be created on views, tables are the fundamental object for which triggers are defined.

Multiple choice technology databases
  1. SELECT * FROM Persons WHERE FirstName='%a%'

  2. SELECT * FROM Persons WHERE FirstName='a'

  3. SELECT * FROM Persons WHERE FirstName LIKE '%a'

  4. SELECT * FROM Persons WHERE FirstName LIKE 'a%'

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

The SQL LIKE operator with 'a%' matches any string starting with 'a'. The % wildcard matches zero or more characters. Option A ('%a%') would match any string containing 'a' anywhere. Option B is exact equality. Option C ('%a') matches strings ending with 'a'.

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

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

  3. SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'

  4. None

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

The correct SQL uses WHERE with AND operator to combine two conditions. Option A uses <> which means 'not equal'. Option B has incorrect syntax - column names appear before FROM. The correct syntax is SELECT * FROM table WHERE column1='value1' AND column2='value2'.

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

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

The BETWEEN operator in SQL is inclusive - it includes both endpoint values. Option A uses > and < which are exclusive and would exclude 'Hansen' and 'Pettersen'. Option C has incorrect syntax with column names before FROM. The BETWEEN operator is the cleanest solution for range queries.

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

  2. SELECT * FROM Persons SORT 'FirstName' DESC

  3. SELECT * FROM Persons ORDER BY FirstName DESC

  4. SELECT * FROM Persons ORDER FirstName DES

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

The correct SQL syntax uses ORDER BY (not SORT BY) with DESC for descending order. Options A and B use SORT BY which is incorrect. Option D has incomplete DESC keyword and missing BY. The standard syntax is: SELECT * FROM table ORDER BY column DESC.

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

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

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

  4. None

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

The correct SQL syntax for inserting a record is INSERT INTO table_name VALUES (value1, value2...). Option C shows this correctly. Options A and B have incorrect syntax (INSERT VALUES instead of INSERT INTO VALUES, and INSERT ... INTO instead of INSERT INTO ...).

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

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

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

  4. None

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

When inserting into specific columns, use INSERT INTO table_name (column1, column2...) VALUES (value1, value2...). Option C correctly shows inserting into the LastName column only. Options A and B have incorrect syntax.

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

  2. DELETE FROM Persons WHERE FirstName = 'Peter'

  3. DELETE FirstName='Peter' FROM Persons

  4. None

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

The standard SQL syntax to delete specific records from a table is 'DELETE FROM table_name WHERE condition'. Thus, 'DELETE FROM Persons WHERE FirstName = 'Peter'' is correct.

Multiple choice technology databases
  1. SELECT COLUMNS() FROM Persons

  2. SELECT COUNT(*) FROM Persons

  3. SELECT COUNT() FROM Persons

  4. SELECT COLUMNS(*) FROM Persons

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

To count records in SQL, use the COUNT(*) aggregate function. Option B shows the correct syntax. COUNT() without asterisk (option C) is incomplete, and SELECT COLUMNS() is not valid for counting records.