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 sql
  1. DATETIME

  2. INT

  3. SMALLDATETIME

  4. VARCHAR

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

Washington's birthday (1732) is before the minimum DATETIME value (January 1, 1753). INT can store dates as integers (e.g., YYYYMMDD format) covering any historical date. SMALLDATETIME has the same 1753 limitation. VARCHAR would work but is not ideal for date calculations or sorting.

Multiple choice sql-server
  1. The catalog is not populated

  2. You did not create a unique SQL Server index on the ProductName column

  3. The SQL ServerAgent Service is not running

  4. The Microsoft Service is not running

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

Full-text indexes in SQL Server must be populated (crawled) before they return results. If the index is defined but the catalog hasn't been populated with the actual data from the columns, queries will return empty results even if the search terms exist.

Multiple choice sql
  1. Indexed view

  2. procedures

  3. triggers

  4. views

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

SQL Server indexed views have strict limitations to ensure determinism and performance optimization. SELF JOINs are not allowed in indexed views because they create circular dependencies that make it difficult for the query optimizer to maintain the indexed view's integrity. Regular views, stored procedures, and triggers can all use SELF JOINs without restrictions.

Multiple choice qn10
  1. Insert

  2. Delete

  3. Update

  4. Select

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

To solve this question, the user needs to know about the differences between various SQL commands and their effects on the database.

The ExecuteNonQuery method is used to execute SQL commands that do not return any data. Instead, it is used to execute commands that modify the data in the database.

Now, let's go through each option and explain whether or not it suits the ExecuteNonQuery method:

A. Insert: This option is correct. The Insert command is used to insert new data into a table, which changes the data in the database. Therefore, ExecuteNonQuery is suitable for executing Insert commands.

B. Delete: This option is correct. The Delete command is used to delete data from a table, which changes the data in the database. Therefore, ExecuteNonQuery is suitable for executing Delete commands.

C. Update: This option is correct. The Update command is used to modify existing data in a table, which changes the data in the database. Therefore, ExecuteNonQuery is suitable for executing Update commands.

D. Select: This option is incorrect. The Select command is used to retrieve data from a table and return it to the user. It does not modify the data in the table, so ExecuteNonQuery is not suitable for executing Select commands.

Therefore, the answer is: D.

Multiple choice sql
  1. Distinct

  2. Unique

  3. Exclusive

  4. Discrete

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

DISTINCT is the correct SQL keyword to eliminate duplicate rows from query results. It's used in the SELECT clause like 'SELECT DISTINCT column_name'. UNIQUE is a constraint for table definition, not a query clause.

Multiple choice sql
  1. COUNT()

  2. SQRT()

  3. AVG()

  4. ALL OF THESE

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

SQRT() is a scalar function that returns a single value (square root). COUNT() and AVG() are aggregate functions that work on multiple rows and return a single aggregated value. The question asks for a single-value (scalar) function.

Multiple choice sql
  1. grant

  2. revoke

  3. rollback

  4. none

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

ROLLBACK is a Transaction Control Language (TCL) command that undoes transactions, while GRANT and REVOKE are Data Control Language (DCL) commands used for permissions. TCL includes COMMIT, ROLLBACK, and SAVEPOINT for managing database transactions.

Multiple choice sql
  1. Data types

  2. Primary keys

  3. Default values

  4. All of the above.

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

When creating a table in SQL, you need to consider multiple aspects: data types for each column, primary keys to uniquely identify rows, and default values for columns. These are fundamental components of table definition in SQL CREATE TABLE statements. Ignoring any of these can lead to poor database design or errors. Therefore, all of these factors must be considered when designing a table.

Multiple choice sql
  1. DDL

  2. DML

  3. HTML

  4. XML

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

To solve this question, the user needs to have knowledge of SQL and its different components. In particular, the user needs to understand the purpose of SQL query and modification commands.

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

A. DDL: This option is incorrect. DDL stands for Data Definition Language and is used to define and manage the structure of a database. DDL commands include CREATE, ALTER, and DROP. While DDL commands are part of SQL, they are not specifically related to SQL query and modification commands.

B. DML: This option is correct. DML stands for Data Manipulation Language and is used to retrieve, insert, update, and delete data in a database. DML commands include SELECT, INSERT, UPDATE, and DELETE, which are commonly used in SQL queries and modifications.

C. HTML: This option is incorrect. HTML stands for Hypertext Markup Language and is used for creating the structure and presentation of web pages. HTML is not related to SQL query and modification commands.

D. XML: This option is incorrect. XML stands for Extensible Markup Language and is used for storing and transporting data. XML is not directly related to SQL query and modification commands.

The Answer is: B. DML

Multiple choice sql
  1. SELECT NAME IN CUSTOMER WHERE STATE IN ('VA');

  2. SELECT NAME IN CUSTOMER WHERE STATE = 'VA';

  3. SELECT NAME IN CUSTOMER WHERE STATE = 'V'

  4. SELECT NAME FROM CUSTOMER WHERE STATE IN ('VA');

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

Using IN with a single-value list is equivalent to using = for comparison. Both queries return names of customers from Virginia. The IN operator is typically used with multiple values, but works identically with one.