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

Multiple choice technology databases
  1. MAX

  2. TOP

  3. MOST

  4. UPPER

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

To retrieve a maximum value in SQL, the user needs to know the appropriate keyword that retrieves the highest value from a column. The correct option is:

The Answer is: A

Option A: MAX is the correct keyword used to retrieve the maximum value from a column. It is an aggregate function in SQL that takes the column name as input and returns the highest value in that column.

Option B: TOP is a keyword used to limit the number of rows returned from an SQL query. It does not retrieve the maximum value from a column.

Option C: MOST is not a valid SQL keyword.

Option D: UPPER is a keyword used to convert a string to uppercase in SQL. It does not retrieve the maximum value from a column.

Multiple choice technology databases
  1. Determines if a value matches any of the values in a list or a sub-query.

  2. Defines the tables we are selecting or deleting data from.

  3. Is used with the DISTINCT SQL keyword only.

  4. Is used to select data from a view

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

The IN operator in SQL is a logical operator used in a WHERE clause to determine if a specified value matches any value in a literal list or a subquery. The other options describe the FROM clause or are unrelated to the purpose of the IN keyword.

Multiple choice technology databases
  1. a special type of table

  2. a special type of store procedure, executed when certain event occurs

  3. a special type of view

  4. an event

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

A trigger in SQL is a special type of stored procedure that automatically executes in response to specific database events like INSERT, UPDATE, or DELETE operations on a table. Unlike regular stored procedures that must be called explicitly, triggers fire automatically when their defined event occurs.

Multiple choice technology databases
  1. LEFT

  2. LEN

  3. AVG

  4. JOIN

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

AVG is a standard SQL aggregate function that calculates the arithmetic mean of numeric values in a column. Other common aggregate functions include SUM, COUNT, MIN, and MAX, all of which perform calculations on multiple rows and return a single result.

Multiple choice technology databases
  1. Alter table Tbl_Test Insert column New_Column varchar 20

  2. Alter table Tbl_Test Alter column New_Column varchar 20

  3. Alter table Tbl_Test add New_Column varchar 20

  4. Either a or b could be used

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

ALTER TABLE with ADD clause is used to add a new column to an existing table. The correct syntax is 'ALTER TABLE table_name ADD column_name datatype'. INSERT and ALTER are not used in this context.