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 databases
  1. List of columns that will be selected or the * symbol.

  2. The JOIN SQL clause.

  3. The name of the table we are selecting from.

  4. Selects a database

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

The SELECT clause is immediately followed by the list of column names to retrieve or the asterisk (*) wildcard for all columns. The FROM clause specifying the table comes after SELECT.

Multiple choice technology databases
  1. Having Clause

  2. Where clause

  3. Distinct

  4. Exists

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

HAVING clause filters groups after aggregation, while WHERE clause filters individual rows before grouping. HAVING is used to specify conditions on the groups created by GROUP BY, such as showing only categories with total sales above a threshold. WHERE cannot be used with aggregate functions, whereas HAVING can.

Multiple choice technology databases
  1. Work as primary key

  2. Uniquely identify the records

  3. show a relation between the primary key and unique key

  4. All of the above

  5. None of these

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

Identity columns are auto-incrementing columns that automatically generate unique numeric values for new rows. While they often serve as primary keys, that's not their definition - they're specifically about auto-generated sequential values. Options A, B, and C describe possible USES or characteristics, not the definition. The question asks 'what IS', not 'what does it DO', making 'None of these' the technically correct answer as none define what an identity column fundamentally is.

Multiple choice technology databases
  1. DML Trigger

  2. Instead of Trigger

  3. DDL Trigger

  4. Nested Trigger

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

DDL (Data Definition Language) triggers fire when CREATE, ALTER, DROP, GRANT, DENY, REVOKE, or sp_rename statements are executed on database objects. DML triggers respond to INSERT, UPDATE, DELETE operations on data. INSTEAD OF triggers replace the triggering action. Nested triggers refer to trigger chains, not a specific type.

Multiple choice technology databases
  1. Change the primary key index to clustered and create a nonclustered index on the address

  2. Create a nonclustered index on the address.

  3. Create a clustered index on the address.

  4. Change the primary key to the address and make the index clustered.

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

A clustered index determines the physical order of data in the table. To put data into address sequence, you need a clustered index on the address fields. Only one clustered index can exist per table (unlike nonclustered indexes), and the primary key's nonclustered index doesn't prevent creating another clustered index on a different set of columns.

Multiple choice technology databases
  1. The AS SQL clause is used change the name of a column in the result set or to assign a name to a derived column.

  2. The AS clause is used with the JOIN clause only.

  3. The AS clause defines a search condition.

  4. The AS clause defines a group

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

The AS clause is used to alias columns - either renaming existing columns in results (SELECT col AS new_name) or naming derived columns (SELECT price * qty AS total). It makes output more readable and allows referencing computed values by name.

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

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

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

  4. SELECT * FROM Contest IN ContestDate < '05/25/2006'

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

SELECT * FROM Contest WHERE ContestDate >= '05/25/2006' is correct. The WHERE clause filters rows based on the date condition, and >= selects dates on or after May 25, 2006. Option C uses < (wrong direction), B uses HAVING (for aggregated data), and D has invalid syntax.

Multiple choice technology databases
  1. INSERT INTO Projects (ProjectName, ProjectDescription) VALUES ('Content Development', 'Website content development project')

  2. INSERT Projects VALUES ('Content Development', 'Website content development project')

  3. INSERT Projects ('Content Development', 'Website content development project')

  4. SAVE INTO Projects (ProjectName, ProjectDescription) VALUES ('Content Development', 'Website content development project')

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

To insert data into a table called Projects, the user needs to use the INSERT statement.

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

A. INSERT INTO Projects (ProjectName, ProjectDescription) VALUES ('Content Development', 'Website content development project'): This option is correct. This statement inserts data into the Projects table by specifying the column names (ProjectName and ProjectDescription) and their respective values ('Content Development' and 'Website content development project').

B. INSERT Projects VALUES ('Content Development', 'Website content development project'): This option is incorrect because it does not specify the column names. The correct syntax is to use INSERT INTO, followed by the table name and then the column names and values.

C. INSERT Projects ('Content Development', 'Website content development project'): This option is incorrect because it is missing the INTO keyword. The correct syntax is to use INSERT INTO, followed by the table name and then the column names and values.

D. SAVE INTO Projects (ProjectName, ProjectDescription) VALUES ('Content Development', 'Website content development project'): This option is incorrect because there is no SAVE keyword in SQL. The correct syntax is to use INSERT INTO, followed by the table name and then the column names and values.

Therefore, the correct answer is: A. INSERT INTO Projects (ProjectName, ProjectDescription) VALUES ('Content Development', 'Website content development project')

Multiple choice technology databases
  1. SELECT * FROM Sales

  2. DELETE FROM Sales

  3. SELECT * FROM SALES WHERE OrderID < 1

  4. SELECT FROM Sales

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

SELECT * FROM Sales is the correct syntax to retrieve all columns and all rows. Option B deletes data, C adds a WHERE filter (not all rows), and D is invalid syntax - SELECT requires specifying columns or *.

Multiple choice technology databases
  1. DELETE FROM SalesData

  2. DELETE * FROM SalesData

  3. DELETE SalesData

  4. DELETE ALL SalesData

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

To solve this question, the user needs to know the basic syntax of the SQL DELETE statement. The correct answer is:

The Answer is: A

Explanation:

A. DELETE FROM SalesData: This option is correct because it follows the correct syntax for deleting all rows from a table. The DELETE statement is used to delete existing records in a table, and the FROM keyword specifies the table from which to delete the rows. So, this statement will delete all rows from the SalesData table.

B. DELETE * FROM SalesData: This option is incorrect because it does not follow the correct syntax for the DELETE statement. The asterisk (*) is not required in the DELETE statement and may cause an error.

C. DELETE SalesData: This option is also incorrect because it does not follow the correct syntax for the DELETE statement. The table name should be preceded by the keyword FROM, which is missing in this option.

D. DELETE ALL SalesData: This option is incorrect because it also does not follow the correct syntax for the DELETE statement. The keyword ALL is not necessary and will cause an error.

Multiple choice technology databases
  1. To return the minimum value of a numeric expression.

  2. To return the absolute, positive value of a numeric expression.

  3. To return the maximum value of a numeric expression.

  4. To return the average value of a numeric expression.

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

The ABS function returns the absolute (positive) value of a number, converting negative values to positive while leaving positive values unchanged. For example, ABS(-5) returns 5, and ABS(3) returns 3. It's useful for distance calculations or magnitude comparisons.

Multiple choice technology databases
  1. INSERT clause

  2. SELECT clause

  3. DELETE clause

  4. JOIN clause

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

The HAVING clause is used to filter groups of rows created by the GROUP BY clause, which is a component of a SELECT statement. It cannot be used with INSERT, DELETE, or JOIN clauses directly, as they do not support group-level filtering.